Anyone working with WordPress (or any other PHP based system) had a chance to see one of the most common fatal errors PHP has to offer: Allowed memory exhausted. This is easy to fix, and depending on your host and personal preference, there are several methods to do it.
Older WordPress versions (before 2.9) could work with 16M of PHP memory. Even later, 3.x versions can work with so little memory if you don’t use any plugins. But, using plugins increases memory requirements, and using only 32M is, at most times, not enough. For the latest WordPress with an average of 20 plugins, you will need 48M to 64M. Most hosting companies keep this value at 32M, so when you upgrade WordPress, upgrade the plugin or add new plugins, you will run out of memory, and you will see the variation of this error (on-screen or in the log, depending on server settings):
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 345234 bytes) in /path/to/public_html/wp-content/plugins/plugin.php on line 56.
To increase memory, you can use different methods. The examples below are for 64MB of memory. You can set it lower and experiment with higher values. Setting this to 128M or 256M is fine; PHP will really use it as needed; this value is limited. Use only one of these methods, don’t use all of them at the same time!
Method 1: Change PHP.ini
On some shared hosting servers and on VPS or other dedicated hostings, you will have access to the php.ini file with all main PHP settings. This file should have a memory directive, so you need to find it and change it, if it is not there, you need to add it.
Here is the directive you need to find/add and set the different value for memory size:
memory_limit = 64M
Method 2: Use .htaccess
If you don’t have access to php.ini, the same thing can be done using the .htaccess file. This file is in your website’s root folder; if it’s not there, you can add it, but WordPress adds it in most cases. This file is only available on Apache servers. Again, search for this in that file; if it is not there, add it, and set the memory value you need:
php_value memory_limit 64M
Method 3: Use WordPress wp-config.php
WordPress way to do this is using the almighty wp-config.php file. If this define is in the file, change it to the memory value you want; if it’s not there, add it before the “That’s all, stop editing!” comment in that file. Here is the code to find and change or add if not there.
Method 4: Contact your hosting company
If you don’t want to do it yourself, you can always contact your hosting company support. Some hosting companies can impose a limit on this value, so whatever you try to change, it will fail, and only hosting support can change it for you (if they want to). If you can’t change the memory limit, it is time to find better hosting that will allow you to do so.