Done in 60 seconds: change memory_limit on shared hosting in D7

If you're using shared hosting, you may not have control over your master php.ini file, which amongst other things is used to set the maximum amount of memory your site is allowed to use. In addition, your D7 sites/default/settings.php has this line

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

but on your shared host you may find that despite the above setting the Reports >> Status report of your site still only quotes a meagre value of 40M or so. For all but the smallest sites, this is not enough. Load up the Views module and you're likely to hit the "white screen of death" on many a page, in particular the admin/modules page.

Copying the above line to your index.php file is not going to help.

The simple way around this in D6 used to be to create a second php.ini file in which the memory_limit is increased and to place this in the root of your website, i.e. in the same directory as the index.php file.

Do this in D7 and you're likely to get an error like this: "Fatal error: Class 'PDO' not found in ....".

The solution is to still create the php.ini file, but to put two extra lines at the top before setting memory_limit:

; Required in D7 in order for memory_limit to work
extension = "pdo.so"
extension = "pdo_mysql.so"
memory_limit = 64M

Easy, but not so obvious at first!

View more tips and tricks...

File under: 

27 reasons NOT to use Google Maps... and 2 to do so

Read More »