How to increase the PHP memory_limit
Posted: Mon Sep 25, 2023 3:24 pm
At times, you might come across the error message: "Fatal Error: Memory Size Exhausted," or perhaps your website simply displays a blank page? This issue commonly arises when installing a new theme, incorporating a plugin, or updating the WordPress version. Is the website operating at a reduced speed or experiencing server overload?
The primary source of this error is your host's PHP memory_limit being insufficient for your process's requirements. In such instances, it becomes necessary to enhance the host memory limit to ensure process completion.
The PHP memory_limit can be configured to limit the amount of memory scripts are permitted to allocate, measured in bytes. This configuration is beneficial to prevent ill-coded scripts from consuming the entire server's memory.
Increasing PHP memory_limits might be necessitated for various other purposes. The default memory limit of PHP can differ, contingent on the server's setup.
The default PHP settings suffice for operating most websites with every PHP installation. However, to cater to specific requirements of a website, occasional adjustments in PHP settings might be requisite. Accordingly, it might be imperative to augment the memory_limit on your site to facilitate the conclusion of a process.
For example, let's say you want to change memory_limit for example.com
First, check what PHP version you run on the example.com domain.
In your SSH run:
For this domain, the resulting output will be:
Now in your SSH, as root, edit it's FPM conf file:
In this file path example, the PHP version is 8.0 and the domain is example.com.
Edit:
To apply your desired modifications, simply restart PHP-FPM by executing the following command:
(in case when you use some other PHP version different than 8.0, just change 8.0 to propper version)
The primary source of this error is your host's PHP memory_limit being insufficient for your process's requirements. In such instances, it becomes necessary to enhance the host memory limit to ensure process completion.
The PHP memory_limit can be configured to limit the amount of memory scripts are permitted to allocate, measured in bytes. This configuration is beneficial to prevent ill-coded scripts from consuming the entire server's memory.
Increasing PHP memory_limits might be necessitated for various other purposes. The default memory limit of PHP can differ, contingent on the server's setup.
The default PHP settings suffice for operating most websites with every PHP installation. However, to cater to specific requirements of a website, occasional adjustments in PHP settings might be requisite. Accordingly, it might be imperative to augment the memory_limit on your site to facilitate the conclusion of a process.
For example, let's say you want to change memory_limit for example.com
First, check what PHP version you run on the example.com domain.
In your SSH run:
Code: Select all
sudo /usr/local/vesta/bin/v-get-php-version-of-domain example.com
Code: Select all
8.0
Code: Select all
sudo mcedit /etc/php/8.0/fpm/pool.d/example.com.conf
Edit:
Code: Select all
php_admin_value[memory_limit] = 512M
Code: Select all
sudo systemctl restart php8.0-fpm