1. Code snippets

Increase PHP memory limit in WordPress

The most encountered error in WordPress installs these days is the “memory exhausted” error.

We get this error while we’re trying to install / activate / update plugins and themes or while we try to do memory intensive tasks inside our WordPress sites.

Fatal error: Allowed memory size of xxxxxxxx bytes exhausted (tried to allocate xxxx bytes) in …..

What is this memory limit ?

Firstly WordPress itself sets a limit by default at 40Mb of ram memory to be used at each page accessed, and secondly our web hosting configuration commonly have this limit set to an average of 64Mb.

Why we get this error ?

A fresh install of WordPress won’t exceed this default memory limits, but as we expand WordPress to do more and more stuff using advanced plugins or custom functions the amount of memory needed to render a page also increases.

For example WooCommerce recommend setting a minimum of 96Mb while other plugins might require you to increase this limit to 128Mb or even more.

How we can fix it ?

In order to fix this error we’ll have to do two things:

1) Increase default WordPress memory limit:

To do this you will need to use your favorite FTP client and connect to view and edit your site files.

In the main folder of your site, there where you have WordPress installed, you should look after the wp-config.php file, once you located it you will have to edit it and follow this steps:

– find the line which contains the following code:

define(‘WP_DEBUG’, false);

– after this line you will have to add this piece of code:

define(‘WP_MEMORY_LIMIT’, ‘128M’);

Some hosting environments only require this step to be made so after this point you can give a try and see if the memory exhaust error still persists, if the error is still present then please continue with the second step.

2) Increase your hosting PHP memory_limit:

This can be made using the php.ini or .htaccess files which should be located in the main folder of your WordPress site.

If you don’t manage to find any of this files then you will have to create them, again as in the first step, you should use a FTP client to connect and create or edit this files.

You should firstly try to change the limit from the php.ini file, by adding the following line into it:

memory_limit 64M;

Secondly, if the first method didn’t had success, try to change the limit from the .htaccess file, by adding the following line into it:

php_value memory_limit 64M

If you encounter any error while trying to set the memory limit using any of this two methods then it means your hosting provider has locked this settings and you will have to contact their support department and ask them to increase this limit to the value you desire.


Hope this small tutorial was clear enough to help you fix this very common error.



Do you like SeventhQueen's articles? Follow on social!