Out of memory on a WordPress server, or what to do about php memory_limit

Today, logging into the blog admin, I got this error:

Allowed memory size 67108864 bytes exhausted (tried to allocate 139650 bytes) ../class.wp-scripts.php on line 154

The blog itself works, but I can’t get into the admin. Since it’s hosted on shared hosting, on a free account no less, I got a bit worried — I suspected I wouldn’t be able to raise the php memory limit.

There are a few options for situations like this:

  1. Raise php_memory_limit in .htaccess:
    php_value memory_limit 128M
    

Unfortunately this might not work if your host’s apache config has AllowOwerride none

  1. Raise php_memory_limit from php itself. Add this line to index.php:
    ini_set('memory_limit', '128M');
    

The annoying part: if your host has safe_mode enabled in php, this option won’t help either.

  1. Add the following to wp-config.php:
    define( 'WP_MEMORY_LIMIT', '128M' );
    

Log into the admin and enjoy life. Maybe disable a couple of plugins while you’re there.