Increase PHP memory limit in WordPress
Sometimes when you are trying to perform a normal WordPress action like activating a plugin, you get an error message like this:
Fatal error: Allowed memory size of 157286400 bytes exhausted (tried to allocate 5775295 bytes)
If you are running resource-intensive plugins like WooCommerce, or maybe if your host is stingy with resources, you can find yourself hitting that error.
This means that PHP, the language that WordPress runs on, needs to be able to use more memory to complete the task you just attempted.
The solution is to increase the amount of memory allocated to PHP.
There are a few ways to do this, and you may or may not be limited by your host, in which case, if the following fixes don’t work, you need to talk to them. If you max out your memory and continue to have problems, the issue might be a problematic plugin, or some poor code in your theme.
Make sure you run an up-to-date version of PHP since older ones are less efficient.
WooCommerce recommends at least 64M. 128M should be enough for most sites, but if you run resource intensive plugins, you may have to go higher. You can increase it incrementally until you can complete the task that triggered the message.
To increase the memory limit for the administration area:
define( 'WP_MAX_MEMORY_LIMIT', '256M' );
If you find that defining the limit in the wp-config file is not working, you might have to address it a level up - that is in your PHP configuration file, known as php.ini.
Depending on your host, you may or may not have access to this file, and you may or may not be able to create your own. Search your webhost’s knowledge base for php.ini and you should come up with where to locate the file.
Then add, or adjust the following line:
memory_limit = 128M ; Maximum amount of memory a script may consume (128MB)
If you don’t have access to your php.ini file, sometimes you can use your .htaccess file to set the memory limit:
php_value memory_limit 128M<br>