Share this:

Technorati ReddIt Favorites

Increase PHP Memory Limit

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 latest WordPress with average of 20 plugins you will need 48M to 64M. Most hosting companies keep this value at 32M, so when you upgrade WordPress, upgrade plugin or add new plugins, you will run out of memory and you will see variation of this error (on screen or in 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 uses different methods. Examples bellow are for 64MB of memory. You can set it lower and experiment with higher values. Setting this to 128M or 256M is fine also, PHP will really use as needed, this value is limit. Use only one of these methods, don’t use all of them in 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 php.ini file with all main PHP settings. This file should have 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 different value for memory size:

memory_limit = 64M

Method 2: Use .htaccess

If you don’t have access to php.ini, same thing can be done using .htaccess file. This file is in the root folder of your website, if it’s not there you can add it, but in most cases it is added by WordPress. This file is only available on Apache servers. Again, search for this in that file, if it is not there add it, and set memory value you need:

php_value memory_limit 64M

Method 3: Use WordPress wp-config.php

WordPress way to do this is using almighty wp-config.php file. If this define is in the file, change it to memory value you want, if it’s not there add it before “That’s all, stop editing!” comment in that file. Here is the code to find and change or add if not there.

define('WP_MEMORY_LIMIT', '64M');

Method 4:  Contact your hosting company

If you don’t want to do it on your own, you can always contact your hosting company support. Some hosting companies can impose limit to this value, so no method you can try can change it, and only hosting support can change it for you.

GD Press Tools: PHP Status

GD Press Tools: PHP Status

Check current memory limit and memory usage

Simplest way is to use our GD Press Tools plugin (you can see this with both Lite or Pro version). On GD Press Tools main page you can see the PHP Status block, and there you can find Memory Limit item and value for it. How much memory is used, plugin can add into the footer, and image bellow shows you used memory during the page creation, footer value is most important, that is total memory used for the whole page.

GD Press Tools: Memory usage

GD Press Tools: Memory usage

Admin side uses about twice as much memory then front end side.

5 Responses to “Increase PHP Memory Limit”

  1. Soverato News | July 24, 2011 at 18:20

    …and this is also possible with shared hosting?

    • MillaN | July 25, 2011 at 00:48

      Yes, with most of them it is. At least one of the methods should work. Some shared hosting companies will even allow use of shared php.ini.

  2. ionut | August 23, 2011 at 16:26

    i’ve tried to increase it before, but everytime by editing the wp_config.php file. it didn’t work. i don’t know why. Now i’ve edited the htaccess file and guess what? it works perfect.
    Thanks a lot

    • MillaN | August 23, 2011 at 16:41

      On some servers administrators disable some of the PHP functions like the one used to increase memory based on wp-config.php value.

  3. JamieB | May 17, 2012 at 14:30

    After having tried all the solutions above and finding no other ones online we finally discovered an issue that some of your other readers may not have contemplated:

    Go to your sever settings, we use Parallels and check that your advanced hosting settings are set for Apache and not CGI/Fast CGI as ours were.

    Embarrassment all round.

Leave a Reply

Follow us on Twitter

Date Archives

Social Networks

Google Plus Profile Subscribe to RSS feed LinkedIn Profile Follow me on Pinterest Watch our Youtube Videos Find us on Flickr

Feedburner Feedburner updates

Sign up to receive news from this website to your email.

Recent Blog Posts

Dev4Press on YouTube

Share This

Technorati ReddIt Favorites