Last updated December 24, 2014. Created on January 6, 2008.
Edited by joachim, Christopher James Francis Rodgers, bserem, 1q84. Log in to edit this page.



Note: increasing PHP

'Php-Memory limit' is different from increasing 'PHP-upload' size limit.

You can learn to increase upload size on page: 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.

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.

.user.ini in public_html folder (for PHP 5.3 and up)

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.

.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.

Tools

For Drupal 6 you might want to try the Drupal Tweaks module which allows you to increase your PHP memory limit without editing any files.

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

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

As If’s picture

If you're running a WHM-powered VPS you may find that you do not have permissions to edit PHP.INI directly; the system must do it. In the WHM host control panel, go to Service Configuration > PHP Configuration Editor.

-------------------------------------------
Interactive Worlds and Immersive Obsessions
http://www.asifproductions.com

marclauren007’s picture

In Plesk under that Websites and Domains tab you can click on the domain name in question. Then you will see a PHP Settings tab after clicking on the domain name, this screen will allow you to change the most common PHP settings, including the upload limit.

---Hope this helps

texas-bronius’s picture

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.

To add to confusion, note that at least in the case of 1and1.com, phpinfo() actually responded with the higher memory_limit setting placed in settings.php, however the memory_limit was still the system-enforced 30MB. This observation was confirmed by 1and1 support. Also, fwiw, this memory limit is imposed on concurrent activity on the account overall, not per website on the account.

--
http://drupaltees.com
80s themed Drupal T-Shirts

stevegmag’s picture

1and1 indeed does have a 30M memory limit on their shared plans.

This will run a basic drupal 6 install, but not much more, certainly not a Drupal 6 install with "default" contrib modules (CCK, Veiws, etc..). I thought I had resolved the issue via php.ini, htaccess, or drupal settings as phpinfo will report that you're memory has been increased, but the site memory errors always report that there is only 30M available. I called 1and1 today and confirmed that no such limit is in place on their cloud, VPS, or dedicated plans, but I have not confirmed that in practice yet..

http://faq.1and1.com/scripting_languages_supported/php/9.html

sg

jahmes8’s picture

Try using the file name php5.ini instead.

I found this to work on some hosting providers (GoDaddy, BlueHost among my managed sites). Just putting php.ini in the root didn't change the limit in the Status Report. I renamed it to php5.ini and then it registered.

I hope it helps.

James

loopduplicate’s picture

I also specify the limit in settings.php like the example below. Do you?

ini_set('memory_limit', '256M');

Christopher James Francis Rodgers’s picture

For a detailed step-by-step solution to the memory error problem
"Fatal error Allowed memory size of"
for both Drupal 6 and Drupal 7 to easily increase the memory allocation to 128M, see...

Drupal 7 Fatal error Allowed memory size of ...
http://drupal.org/node/76156#comment-4582924

..or..

Drupal 7 memory increase to more than 128M,
that may or may not work for Drupal 6, see...
http://drupal.org/node/76156#comment-4583384

"All the best; intended."
- Chris
___

Drupal 8 is great.

Re: Drupal 9,000
Three-minute Video on the problem
of technology out-pacing users.
http://great-grandma.com/gil_bates-dead_at_42/index.html

mfby2k’s picture

The setting.php method worked for me know my site www.daenotes.com run with out the error message. [memory exhausted......] thanks for the info.

Alex v. B.’s picture

sridharpandu’s picture

In PHP.ini I can set memory_limit = -1 to indicate "no memory limit" use all that is available. Can I do this in settings.php ini_set('memory_limit', '-1'); to have the same effect?

Best regards

Sridhar

Acer Aspire 5745
[i5 430M, 3GB, 320GB]
Ubuntu 12.04 (Precise Pangolin)
Drupal 6.15, 7.x
DigitalOcean, Go Daddy, Rackspace,

asb’s picture

@sridharpandu: Maybe you want to try this out? It shouldn't be too hard to change the parameter and go to the status report page.

However, for people running Suhosin patch this setting is neither valid in php.ini nor anywhere else (and is handled as an illegal attack).

sridharpandu’s picture

@asb, I am running all my sites with suhosin! I just used it on one ocassion on a slicehost VPS, I didn't install the suhosin patch though. But as of now all the sites I run have the suhosin patch.

Acer Aspire 5745
[i5 430M, 3GB, 320GB]
Ubuntu 12.04 (Precise Pangolin)
Drupal 6.15, 7.x
DigitalOcean, Go Daddy, Rackspace,

sparcle_z’s picture

php_value memory_limit = "128M"
extension=pdo_sqlite.so
extension=sqlite.so
extension=pdo_mysql.so
# added the file as php.ini and loaded in public_html

robwithhair’s picture

I just had this problem while trying to enable a commerce module. admin/modules/confirm gave me an out of memory warning when enabling price module. Surprisingly I had 128MB available in my php.ini but needed more. If anyone has this problem I'd suggest trying to increase the memory limit to something crazy like 512MB temporarily and to disable and re-enable the module again. Worked for me but I couldn't believe I might need more memory than this. Remember to restart apache after adjusting php.ini file. I've put my memory limit down to 128MB again after enabling the module in question.

yevgeny.ananin’s picture

Hi,

I have 1&1 and they cap their 'Business Linux' shared hosting accounts' php memory limit at 90MB - and they don't offer any accounts with a higher limit. I have recently run into the problem described in these forums: http://drupal.org/node/1397450, http://drupal.org/node/1561450.

I contacted 1&1 and they told me that this error is definitely a php memory error - and that they can't do anything about it. Can anyone recommend a hosting provider who has a higher max php memory limit, like 128M, 256M, or even 512M?

asb’s picture

@yev.ananin: Avoid incompetent managed hosting - if that's what 1&1 is doing, they are incompetent. Go for a root server, or look for a managed hosting that actually supports Drupal. You can find some companies with proven Drupal know-how at the marketplace, or you can drop me an email if you are interested in individual experiences. However, this is not the right place to discuss Drupal hosting, please use the forums for that.

Christopher James Francis Rodgers’s picture

since those all of the links on that page
are drupal® affiliate links
from hosting companies that support Drupal technically;
and financially--
when you use the links on this page:

The Drupal.org "Hosting" page
http://drupal.org/hosting

"All the best; intended."
- Chris
___

Drupal 8 is great.

Re: Drupal 9,000
Three-minute Video on the problem
of technology out-pacing users.
http://great-grandma.com/gil_bates-dead_at_42/index.html

Christopher James Francis Rodgers’s picture

I have now been happy with BlueHost for 4 years.

Use their link on the drupal.org page
http://drupal.org/hosting
and BlueHost will give all of the money
from your initial contract (your initial order)
to Drupal.org. (..if I understand correctly).

I recommend you buy three years at $4.95 / month (or whatever it is today..)
to avoid the hassle
of renegotiating it down from $7.95 (or whatever it is today..)
when your first contract (your first order) expires.
{They so play hard-ball now... 2013.05}

  • Unlimited website storage
  • Unlimited bandwidth
  • 50 MySQL Databases
    {but restricted to 1000-tables = approximately 7 or 8 Drupal-7 sites}

Note:
Using the free BlueHost control panel's
automated Drupal installer
via "SimpleScripts" (I recommend you do not use: Fantastico)
I can 'one-click' install a test Drupal 6 or 7 site;
and the php-memory limit is automatically set to 128M (for Drupal 7).

"All the best; intended."
- Chris
___

Drupal 8 is great.

Re: Drupal 9,000
Three-minute Video on the problem
of technology out-pacing users.
http://great-grandma.com/gil_bates-dead_at_42/index.html

loopduplicate’s picture

I agree with Christopher James Francis Rodgers about Bluehost (or Hostmonster; they are the same company.) I've been using them for about 3-4 years now. For an inexpensive shared server setup, they are amazing.

ChandeepKhosa’s picture

Just a heads up for anyone using Heart Internet shared hosting reseller account - the only method you can use is adding
php_value memory_limit 128M to the file sites/default/settings.php
A good way to test it is see if the status report changes here /admin/reports/status

Kind regards,

Chandeep Khosa
Managing Director
Imagine Creativity : Web Development, Digital Marketing & Training

ravi_admec’s picture

it is really traumatic sometimes. i had to refresh my site more than 10 times too for clearing the cache in drupal 7.
I tried both method 1. php.ini (memory_limit = 128M) and 2. settings.php (ini_set('memory_limit', '128M');) with recommended settings.

yet i am facing the same issue.

Will some one tell me something useful plz.

My website can be found in my signature.

ravi_admec’s picture

hi
i have to solution and used on one of my websites too.

you can notice in previous comment i posted about how i am puzzled.

solution:
create a php5.ini file and put the following line inside that

memory_limit = 256M

and upload in the root of your drupal website.

thanks