Increasing the PHP memory limit for WordPress

Home » Content Management Systems » Increasing the PHP memory limit for WordPress

Most of the shared hosting environments still allocate a memory limit of 32MB to PHP by default, and this, nowadays is simply not enough on a standard WordPress, Drupal or Joomla installation.

This is the reasons for which, in most cases some of the pages (if not all) of the CMS sites return an error similar to the one below:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 24 bytes) in /home/someusername/public_html/pro/wp-content/themes/sometheme/somedirectory/somefile.php on line 31

Resolving this issue is fairly simple, as all you need to do is increase the memory associated with PHP.

1. If you are running WordPress, then this increase can be achieved by adding the following line into your wp-config.php, somewhere at the top of the file:

define(‘WP_MEMORY_LIMIT’, ’96M’);

For more details concerning this change you can check out the WordPress Codex.

2. If the above does not fix the issue, or you’re not running WordPress then you will need to edit your php.ini and add the following line within:

memory_limit = 96M ;Maximum amount of memory a script may consume (96MB)

If you already have a line associated with “memory_limit” in your php.ini simply change it’s value.

Also if your host uses suPHP, you must insure that you have the following lines added into your public_html/.htaccess file:

<IfModule mod_suphp.c> 
suPHP_ConfigPath /home/username/public_html 

You will have to replace the “username” above with your own username. Also if the home path of your account is different you also need to replace the “home” above with the correct home path.

3. If none of the above work, or your host is not using suPHP then you can try to increase the memory limit by adding the following line into your main .htaccess file:

php_value memory_limit 96M

If none of the above work for you, then it’s highly recommended to contact your host and inquire about the memory limitations and memory allowance.

NOTE: It is not recommended to set a memory limit higher than 128MB as while some host providers allocate up to 2GB of memory per customer account, others limit their shared environment to 512MB and higher values could cause severe account stability issues and even more problems. Usually, if a PHP script requires more than 128MB of memory to run then it’s not suitable for a shared environment and consider upgrading to at least a Scalable Cloud plan.