RSS

Tag Archives: DrupalCommons

Drupal: Increase PHP memory limit without access to php.ini

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.

  1. 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.
  2. Edit the memory_limit parameter in the php.ini file (usually in a section called Resource Limits)
    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.
  3. Restart Apache.

php.ini in the Drupal root folder

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.

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 64M

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', '64M');

Shared Hosting

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.
suPHP_ConfigPath ~/public_html

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

Modifying php.ini in local server environments

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.

Check your change has taken effect

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.

Advertisements
 
Leave a comment

Posted by on February 22, 2013 in Tips

 

Tags: , ,

 
%d bloggers like this: