Increase PHP memory limit (3 methods)

Last modified: March 15, 2009 - 07:56

While Drupal core will run with 8 MB of memory configured for your server, you may need to increase this depending on how may modules you use on your site.

In Drupal 4.7.x and earlier, when you go into ?q=admin/modules, you may experience a blank screen. This is caused by Drupal loading all the modules of your site into memory, whether you have them turned on or not. If you get a blank screen here, you have two choices; increase your allocated memory for PHP or delete unused modules.

In Drupal 5.x and above, this problem has been fixed, and the modules page no longer loads all modules. If you are still getting out of memory problems, you should either reduce the number of modules used or increase your allocated memory for PHP.

Depending on your host, this can be done in a number of places with the most likely being php.ini or .htaccess depending on your hosting situation.

Add for example:

  • memory_limit = 16M to your php.ini file (recommended, if you have access)
  • With root access, you can use the sed util in Linux/Unix based systems, in order to increace the memory for 64M. Don't forget to properly locate you php.ini file!

    sed -i 's/memory_limit = 16M/memory_limit = 64M/' /etc/php5/apache2/php.ini

  • ini_set('memory_limit', '16M'); to your sites/default/settings.php file
  • php_value memory_limit 16M to your .htaccess file in the Drupal root

You will need to experiment with the value that is right for you depending on which modules you are using. Some people find they need to set the memory to 24M or 32MB or higher (e.g. 96MB is recommended for a site with built-in image processing using ImageAPI GD).

NOTE: Some hosts do not allow you to control how much PHP memory is available. In this case you will need to work with your host, be very conservative with your module selection and testing or look for a new host that allows more flexibility.

If you're going to have views

gost_ - February 19, 2009 - 17:47

If you're going to have views or any kind of image processing, don't be shy, set to at least 128M!
I recommend 512M, if you can get away with it.

change permissions to edit settings.php

curious-trick - May 11, 2009 - 20:02

A tip for editing settings.php: I tried to edit settings.php and got errors, so I tried uploading an edited version... and got errors. The I remembered that the permissions are set to 555, which means "no one can edit this file", so I changed permissions to 775, added the recommended line and saved, then changed permissions back to 555, and it worked! Note: I did this one a brand new site with no users besides me. It's probably dangerous to edit settings.php on a live site with other users.

On some shared hosts (I use

timpiche - May 12, 2009 - 14:54

On some shared hosts (I use Hostpapa) they allow you to change this by uploading a php.ini file to the root of your domain. This allows you full control of your php settings.

 
 

Drupal is a registered trademark of Dries Buytaert.