In this quick guide, you may see the 4 methods to increase the memory limit for WordPress and WooCommerce. You can see, for example, how to define wp_memory_limit in the wp config php file to raise the memory limit. Issues with low memory can slow down a site or even break it.
Contents
How does an error message about memory limit look like?
Sometimes, you may encounter the following notice (in the system logs or the browser):
Fatal error: Allowed memory size of 12345678 bytes exhausted (tried to allocate 2345678 bytes) in /home/your-username/public_html/wp-includes/plugin.php on line 1000
This error message informs you about the memory limit and tells you how many bytes it was exceeded. There is also a filepath to a file that caused the error and a specific number of a line inside that file. If none of the below methods won't work, then this info can be useful then reporting the error to the plugin developer.
Another version of that error message:
Fatal error: Out of memory (allocated 12345678) (tried to allocate 2345678bytes) in /home/your-username/public_html/wp-includes/plugin.php on line 1000
Both messages tell you that there is no memory left for PHP scripts. It is caused by the server's limit and in most cases changing the server's configuration will solve this issue. However, sometimes server's configuration cannot be changed or the allowed memory limit is very low.
How to increase the WordPress memory limit?
By default, WordPress will attempt to increase the memory allocated to PHP to 40MB for a single site and 64MB for a multisite. If you experience an error shown above, it means that these values are too low. What is the required memory limit? It depends on the plugins you are using. 128 MB is usually enough, but for some plugins, it may be too low.
You can check your memory limit in the WooCommerce System Status (in your WordPress admin panel: WooCommerce > Status).
In some cases, the value displayed in the System Status might not be correct. If the server has a higher limit than the one set for WordPress, then in the Status there will be shown a maximum value for WordPress. The value can also be incorrect if the limit set in wp-config.php is higher than the one in the server settings.
Method 1: Edit php.ini file
You need access to the php.ini file on the server/hosting. It's possible to add the file if there isn't one inside the WordPress installation folder.
Then, you may set the memory limit by changing this line. If your line shows 64M try 128M:
memory_limit = 128M
M stands for Megabytes.
Method 2: Edit .htaccess file
If you don’t have access to php.ini or the above method has failed, please try adding this to an .htaccess file:
php_value memory_limit 128M
.htaccess file is located in the root directory of your WordPress installation.
Method 3: Edit wp-config.php file
Add this to the top of the file, before the line that says, “Happy Blogging” to raise the wp memory limit:
define('WP_MEMORY_LIMIT', '128M');
wp-config.php file is located in the root directory of your WordPress installation.
Method 4: Change your PHP version
It may happen that the solutions listed above will fail.
Hosting providers sometimes do not allow editing the memory limit or the limit is too low. In this case, you should contact your provider and ask him to set a higher memory limit. If the limit won't be high enough, you should change your hosting plan or choose a different hosting provider.
However, there may be also another way of solving this issue. You can change your PHP version to a higher version. New PHP versions are more efficient and often use less memory. If you have such a possibility, change your PHP version to 7.2. You may read more on how to switch the PHP version for WordPress.
You may also check out WP Desk Care - professional support for WordPress & WooCommerce.
WP Desk Plugins →