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

×

Error message

  • Deprecated function: The each() function is deprecated. This message will be suppressed on further calls in _menu_load_objects() (line 569 of /home/flinkco/public_html/includes/menu.inc).
  • Deprecated function: implode(): Passing glue string after array is deprecated. Swap the parameters in drupal_get_feeds() (line 394 of /home/flinkco/public_html/includes/common.inc).

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: 

Drupal 8: contrib roads, take me home

Read More »