Fatal error: Allowed memory size exhausted

Published on 5 Feb 2008 PHP php.ini .htaccess
Fatal error: Allowed memory size of 8388608 bytes exhausted

Ever got that error? It’s PHP telling you you’ve gone overboard on memory usage, and then dying (…wussy). When you’re running Wordpress, you might have encountered this error when trying to activate some plug-in. Wordpress isn’t exactly the thinnest script on the block. I got this error when trying out the stats plug-in Wassup.

To solve it, we need to tell PHP that scripts can use more than the default amount of memory of 8MB. This is usually set in the php.ini file, but on shared hosts you won’t be able to access it. So we have to resort to .htaccess files, which are equally great, but your host might have disabled changing this setting, in which case this fix won’t work.

Wordpress Fix

Here’s to solve it if you’re using Wordpress. For everything else, scroll down!

Go to Site Admin, Select Manage and then Files. Select .htaccess (for rewrite rules), it should be in the list to the right under Common. If not, scroll down and enter .htaccess in Other Files and press Edit file.

Now you should see something like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Just add the following line to it…

php_value memory_limit 16M

…and press Update File. There, now it should work!

General Solution

Browse to a parent directory of your script (any parent, even root, will do). Create a file named “.htaccess”. That’s including the first dot. In that file, enter the following line. If the file already exists, just edit it, and append it.

php_value memory_limit 16M

Now try again.

Still not working?

If it still gives you the error, but now with a different amount of bytes exhausted, the fix is working but you need to set the memory limit even higher. Try increasing 16M to 32M, and so on. Don’t go too high, though! It might just be that your script has a bug that eats up all available memory, in which case you need to check out the code instead of increase the memory limit.
If the error stays the same, your host will probably have disabled the ability to change this setting, and you’re out of luck :( .

David Verhasselt

I’m a consultant & entrepreneur. I build webapps and optimize Minimal Viable Products for clients all over the world. If you'd like to chat, hit me up on david@crowdway.com.

Like this? Sign up to get regular updates
David
Verhasselt