If you’ve recently encountered a memory error on your website there’s a good chance you’re here to learn how to fix WordPress fatal error: allowed memory size of XXX exhausted. The good news is it’s a relatively common error and an easy one to solve. In this guide, you’ll learn how to fix WordPress memory exhausted error by increasing PHP memory
What is WordPress fatal error: allowed memory size of XXX exhausted
WordPress comes packaged with a default PHP memory limit of 32 MB. For small or restrictive hosts and websites with very few plugins or visitors this is often enough memory allocation to power the website. But it is very common to exceed this limit and get the error Fatal error: Allowed memory size, especially as you add more resource-intensive theme and plugins.
A WordPress website runs on PHP and PHP is like any other piece of software that runs on a computer. To efficiently run it needs memory allocated to it. Server administrators will set limits on how much memory applications can use, and PHP is no different. They will set a limit on how much memory PHP can use at any one time. They do this to ensure the hosting runs smoothly.
When a website tries to perform a bigger task you may encounter an error. These days it’s often displayed to you as a message similar to the below example
There has been a critical error on your website. Please check your site admin email inbox for instructions
This is very vague, but on checking your inbox you may see an email that looks like this.
PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 1568768 bytes) in /home/mysitenumber1/domains/mysitenumber1.com/public_html/wp-includes/wp-db.php on line 1995
The moment you see the Allowed memory size of message you know it’s related to memory. How to fix WordPress fatal error: allowed memory size of XXX exhausted?
There are several methods, and we will begin with the most basic and easiest to use. Not all hosts will offer this solution, but if your host does it will offer the easiest solution up to their predefined limits.
How to fix WordPress fatal error: allowed memory size of XXX exhausted
Method 1. Use the PHP selector tool to increase PHP memory limit in WordPress
This is the easiest way to increase PHP memory limit in WordPress. This option is usually restricted to hosts who use CPanel, DirectAdmin and Plesk. Not all hosts who use these control panels will offer this as an option, but the vast majority will.
1. Begin by logging into your hosting control panel and head to the following areas. Please note that each control panel has a different name and if your host may use a different skin.



2. Look for the line that says memory_limit and change the value to something higher from the dropdown. In Cpanel and Plesk you must click apply to save the changes. In DirectAdmin, an Ajax call will apply the changes in the background. As a bonus, you can also change the PHP version on the first page in DirectAdmin.





This should increase the memory limit for your WordPress installation. But what if the values aren’t high enough to stop the error occurring or you’re with a host that doesn’t use one of the supported control panels? The good news is you can still change the values.
Method 2. How to increase WordPress memory limit by editing wp-config
To edit the wp-config file on your WordPress website you will need access to the files with either an FTP client such as Filezilla or access to the control panel file browser if one is provided.
1. Access the root install of your WordPress installation. You will most likely find it in the public_html folder. You will be there when you see three folders called wp-admin, wp-contents and wp-includes. Look for a file below these folders called wp-config
2. Open the wp-config file so you can edit the file and look for the following line near the end of the file
/* That's all, stop editing! Happy blogging. */
3. Just above that line enter the following line of code and save the file
define('WP_MEMORY_LIMIT', '64M');
The above line will increase the PHP memory limit from 32MB to 64MB. You can increase it to other values as needed such as 128, 256, 512 or even 1G. It is a good idea not to set too high a limit, eg. 1G, as it could cause your website to crash and stop loading. If you find that you need to set limits as high as 1G it’s best to troubleshoot why the usage is so high and if there is a way to maintain functionality and reduce the usage needed.
Bonus
As the wp-admin area of your website will always use more memory than the frontend you can also set a higher limit just for admin.
1. Open wp-config again and locate the line that says
require_once( ABSPATH . 'wp-settings.php' );
2. Just above that line enter the following code, adjusting the value to your own needs and click save
define( 'WP_MAX_MEMORY_LIMIT', '256M' );
This will allocate additional PHP memory resources to admin tasks
If you find that this hasn’t fixed the WordPress fatal error: allowed memory size of XXX exhausted error you will need to contact your host or server administrator for further assistance.
Method 3. Use a plugin
I’m going to list this method, but I don’t recommend it for two reasons. Firstly, the plugin hasn’t been updated in over 8 years, so it could have security flaws that can be exploited by hackers. Secondly, if you deactivate the plugin it will revert back to the default values.
1. Begin by installing the plugin Change Memory Limit. The author of the plugin is Simon, whoever he may be. Because it hasn’t been updated in a very long time it will be difficult to find. When I searched for it using the plugin name for this demo it was on page 4. You can follow our guide on how to install a plugin here

2. Once activated you’ll be taken directly to the settings screen which will look like below

3. The plugin will set a default value of 64MB, but you can increase it further by entering a value in MB. eg, 256 for 256MB. Once done click Update
As mentioned, this method is not recommended, but it still appears to work and may be an easy solution for many new to WordPress
Leave a Reply