Increase PHP memory limit for Drupal

A PHP memory limit of 16MB is the minimum requirement for Drupal 6 and 32MB is recommended. Some sites may need more than 32MB if they are using certain contributed modules such as CCK and Views. There are several techniques to increase the PHP memory limit and you only need to use one of them. The right one for you depends on your system configuration.

Install Drupal Tweaks module

If Drupal itself is already installed you could try Drupal Tweaks module which allows you to increase your PHP memory limit without editing any files.

php.ini

This is the recommended approach if you have access to the server’s php.ini. This will not be possible in most shared hosting environments, though your host may be able to adjust it for you. Note that this change will affect all websites and PHP scripts on the server.

1. Locate the php.ini file used by your web server. You can use the phpinfo() PHP function to find it. During installation Drupal checks the PHP Memory Limit and if it is less than 16M an error message also provides the path to the php.ini file.
2. Edit the memory_limit parameter in the php.ini file (usually in a section called Resource Limits)
memory_limit = 32M ; Maximum amount of memory a script may consume (32MB)
If there is no section already for this, place the above line at the end of the file.
3. Restart Apache.

Note: If you are using XAMPP/WAMP, there may be two PHP.ini files (one under the PHP directory and the other under Apache/bin). To change your memory limit, edit the file in the XAMPP/Apache/bin directory.

The next two solutions are more restricted in scope and, in some cases, may be more appropriate choices than affecting all sites.

.htaccess

Edit the .htaccess file in the Drupal root directory. Look for the section:
# Override PHP settings. More in sites/default/settings.php
# but the following cannot be changed at runtime.

and immediately after this add the following line:
php_value memory_limit 32M

This method will only work if PHP is running as an Apache module.

settings.php

If Drupal is already installed, you can edit sites/default/settings.php. This method will affect only the site using this file.

Locate the PHP settings section and add the following line at the end of that section:
ini_set('memory_limit', '32M');

php.ini in the Drupal root folder

Add the following line to a php.ini file in your Drupal root folder:
memory_limit = 32M

This will only work if PHP is running as CGI/FastCGI.

Check your change has taken effect

In all cases, it pays to ensure that your change is actually working. Use phpinfo to verify that your memory actually is what you want it to be. If your change doesn’t seem to be working, double-check the location of php.ini displayed in the phpinfo page. Some systems have multiple copies of that file in different places. Only one is used and the others are red herrings.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.