Last updated August 19, 2011. Created on August 20, 2005.
Edited by LarsKramer, buggs_moran, ChrisRut, VM. Log in to edit this page.

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 increase the memory for 64M. Don't forget to properly locate your php.ini file!

    sed -i 's/memory_limit = .*/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
  • Or simply install: and increase your PHP memory limit in settings.

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.

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


taite11’s picture

It would be nice if there was some more guidance on how to choose a memory limit.

Mine is currently set to 600 on a VPS with 1440 available...I really don't know if that is right or not. Why not just set memory as high as possible?

OhSnapNo’s picture

It's very odd that 16MB or even 32MB is suggested. These are crap values that aren't enough to run modern web sites. Heck, I would be surprised if someone managed to run Drupal with <128MB.

phunster’s picture

128MB is a minimum, I agree with OhSnapNo. It's OK to grant php loads of memory, it only uses what it needs, your just giving php an upper limit. If php is not allocated enough memory, you will meet Drupal's WSOD.

taite11’s picture

So, in my case. If my VPS memory limit is 1440, I should set Drupal to 1440 as well, is that right?

zeptov’s picture

No, you should not. Someone with more Drupal experience than I can provide more guidance, but depending on how your site is set up and what your goals are, you will need to consider the memory usage of MySQL, Apache, and Drupal -- not just PHP. If you search, you'll find lots of guidelines and guidance for setting up memory and when to increase which one, but as with all such guidance your actual needs will vary. At the end of the day, the guidelines and examples that worked for others are exactly that: guidelines and examples that worked for others.

The reason you limit memory is so that a bad module or bad code fails, rather than bringing down Apache or your server.

heyyo’s picture

Is there a way to set php memory limit differently on admin pages ?

hey_germano’s picture

Did you ever figure this one out? I'd like to do the same thing since increasing memory overall will decrease the number of requests the site can handle, and I only run into the memory limit errors in a few places (primary menu admin, admin/content/node list page).

forestmars’s picture

No, I don't think this is possible without hacking core, At least I can't think of a way to do it. It's not that the *AMP stack on which Drupal runs doesn't support this, but that Drupal isn't split into 'front' and 'back' ends, and so any approach to doing this would almost certainly involve a core hack.

By contrast, Joomla CMS has a clear separation of front and back end routing which makes this a trivial operation. Simply set the memory limit in an .htaccess DCF in the /administrator sub-directory and you're good to go.

HTH, Forest Mars

wwwoliondorcom’s picture


Do you know what is now the ini_set('memory_limit', 'xxxx'); limit at Dreamhost ?

How to change it if the default is still at 8M ? Can i add this in my settings.php ?
ini_set('memory_limit', '200M');

Thanks for help.

baff’s picture

I have to set at least 128M in .htaccess - is there a way to find out who consumes a lot of memory?

heyyo’s picture

XHprof seems to be a good solution to find high memory consumption.

nortont’s picture

After about a week of stuffing around and no usefull support from my ISP (CrazyDomains) I eventually got this working.

If I modified .htaccess in the root, no change but modifying it in the Drupal directory caused the site to crash.
Settings.php did not work but did not crash the site. in the site public_html made no difference but in the Drupal root did increase the limit. However the site would crash.

What I found caused the above was I still had the changes in settings.php. Once I removed them, the site came up with another error about "Fatal error: Class 'PDO' not found in /includes/database/ on line 185"

This was fixed by adding the following to my PHP.ini.

memory_limit = 64M

I hope this helps someone else out there.
Oh Happy Days

CaioCosta’s picture

You saved a life today. ;)


nortont’s picture

It's always good to give something back.
I have taken heaps!

EmergeEvolve’s picture

You are a life saver, so pleased you had a crazy domains solution!
Just one addition: The php.ini file with these settings should be in the root of your drupal directory.

wes10’s picture

YOU"RE AWESOME - exactly what i needed (and with CrazyDomains too)
I registered for this site just to thank you.
Much Appreciated :)

nvcken’s picture

I do the following to fix Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 30720 bytes)

# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>
  php_flag magic_quotes_gpc                 off
  php_flag magic_quotes_sybase              off
  php_flag register_globals                 off
  php_flag session.auto_start               off
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_flag mbstring.encoding_translation    off

# I added below
<IfModule mod_php5.c>
  php_value memory_limit 64M

php.ini - created new file at public_html

memory_limit = 64M

settings.php at sites\default\. I add on top of file

ini_set('memory_limit', '64MB');

But that 's not work

Help me please. More detail. ( I use hosting of crazydomain)
I check phpinfo() I also show Memory_limit 30MB

Berliner-dupe’s picture


i use 145 modules for my drupal-project.

I must use min. 256 MB Memory Limit to run this without problems - is this normal by so many modules or is there a problem in my drupal-installation?

In most other threads i read - normal is 128 MB?

Can anyone give my an opinion for this?

(Sorry for my bad english)

Thank you and Regards

datarazor’s picture

256 is not atypical in my opinion if you have a lot of modules and things loading. run xhprof and see where your mem is going. if you use quickstart, it comes with xhprof installed already [as well as everything else you need to debug]

Berliner-dupe’s picture

Thank you very much!

Best Regards

Michael-Inet’s picture

For 145 modules, 256M is probably the minimum. D7 w/ ~30 modules can break 128M.

jahmes8’s picture

I have found that renaming php.ini to php5.ini makes it work when it is not picked up by results.

MGParisi’s picture

Some hosting services require the following line in .htaccess to enable a php.ini file.

suPHP_ConfigPath ~/public_html

drupleg’s picture

I found, in case this is not obvious to others, that adding this line to the end of settings.php didn't work, I had to place the line at the very TOP of the settings.php file for it to work. The site I needed this for is on Pair Networks shared hosting at this time.

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