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!

Privacy Preference Center


We use third-party analytics services to help understand your usage of our services. In particular, we provide a limited amount of your information (such as sign-up date and some personal information like your email address) to 3rd party service and utilize it to collect data for analytics purposes when you visit our website or use our product.

__cfduid,intercom-id-*, intercom-lou-*, intercom-lou-*, intercom-session-*, intercom-session-*, intercom-visitor-session-*


These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site.

All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.

_ga, _gat_gtag_UA_106868094_1, _gid



These cookies are necessary for the website to function and cannot be turned off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.

You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.

PHPSESSID, wordpress_logged_in_*, wordpress_sec_*, wp-settings-time-1, gdpr[privacy_bar], gdpr[allowed_cookies], gdpr[consent_types]