Note: Increasing ‘Php-Memory limit’ is different from increasing ‘PHP-upload’ size limit. You can learn to increase upload size here.
The standard PHP memory requirements for Drupal core are a bare minimum. Sites that run many contrib modules, or particularly memory-intensive ones, will need more. 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.
A typical appropriate memory limit for PHP running Drupal is 128MB per process; for sites with a lot of contributed modules or with high-memory pages, 256MB may be more appropriate.
It’s often the case that the admin section of a site, or a particular page, uses much more memory than other pages. If that is the case, you can conditionally increase memory limits based on the URL of the page.
It’s important to understand that increasing the amount of memory each PHP process can use decreases the number of concurrent processes that can run. Concurrent processes are key to the maximum number of page requests you can serve at any given time.
For example, lets assume a server with 2 GB of memory free for PHP after accounting for other processes running on it (the OS, Apache, and so on).
|PHP memory limit||128MB||256MB||512MB|
|Max number of concurrent processes||16||8||4|
Memory limit/concurrency relationship with 2GB RAM
This is the recommended approach if you have access to the server’s php.ini. This will not be possible in some 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.
- Locate the php.ini file used by your web server. You can click the “more information” link on Drupal’s status page’s PHP section. which shows the phpinfo() page. Locate the Configuration File (php.ini) Path row on that page. During installation Drupal checks the PHP Memory Limit, and if it is less than 32M (16MB for Drupal 6), an error message also provides the path to the php.ini file.
- Edit the memory_limit parameter in the php.ini file (usually in a section called Resource Limits). Make sure you use M to specify the number of megabytes (not MB).
memory_limit = 64M ; Maximum amount of memory a script may consume (64MB)
If there is no section already for this, place the above line at the end of the file.
- Restart Apache.
Add the following line to a php.ini file in your Drupal root folder:
memory_limit = 64M This will only work if PHP is running as CGI/FastCGI.
PHP 5.3+ allows you to change the memory limit by placing a .user.ini file in the public_html folder.
Simply create the above file and type the following line in it:
memory_limit = 64M Some cPanel hosts only accept this method.
The next two solutions are more restricted in scope and, in some cases, may be more appropriate choices than affecting all sites.
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 64M
This method will only work if PHP is running as an Apache module.
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:
In some shared hosting environments, access to the PHP memory limit setting is restricted. If you cannot make the change yourself, please ask your hosting provider to adjust it for you, or look for a new host that allows more flexibility.
For some hosts renaming php.ini to php5.ini may be necessary.
Some hosting services require the following line in .htaccess to enable a php.ini file.
For some hosts (CrazyDomains) you may need to add the following lines to the php.ini file (if they are not there already):
extension=pdo.so extension=pdo_sqlite.so extension=sqlite.so extension=pdo_mysql.so
For MAMP see http://drupal.org/node/66187 particularly the “Optional: Adjust PHP’s memory limit for scripts” section (note the difference for MAMP Pro).
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.
In all cases, it pays to ensure that your change is actually working. Check Drupal’s status report 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. Some systems have multiple copies of that file in different places. Only one is used and the others are red herrings.
XHprof is a good solution to find high memory consumption. See this page for more instructions on how to install and use it: http://groups.drupal.org/node/82889