How to Fix “Fatal Error: Allowed Memory Size of Bytes Exhausted” in WordPress
Table of Contents
WordPress’s “Allowed Memory Size of Bytes Exhausted” is one of the most widespread PHP errors you can encounter. Granted, this error message looks disturbing and can be frustrating to deal with. With it, your WordPress website signals that there is a script using too much of the allocated PHP memory. As a result, your site may show a blank page and become inaccessible, driving your visitors away.
In this article, we will get into what causes the “Memory size exhausted” error and how to increase your PHP memory limit to fix it, so read on.
In the following section, we’ll explain how to fix or troubleshoot WordPress’ “allowed memory size of bytes exhausted” error.
How to Fix This WordPress Memory Limit Error?
If you stumble upon an “Allowed memory size of bytes exhausted” PHP error, it’s likely that your site has consumed all its allocated memory. At this point, you’re probably unsure what exactly could be causing the issue. Therefore, you should first try increasing the WordPress memory limit. There are several ways to do this, depending on your site’s hosting environment.
Increase PHP Memory Limit
The PHP memory limit is the amount of default memory the server allocates to a website’s processing. Different web hosting providers may have different server configurations, although, by default, WordPress’ memory comes preset to 64M.
The default WordPress memory limit value is set to 256 MB. However, on all SiteGround servers, the server PHP memory_limit is configured to 768 MB for all shared plans and can be increased further for Cloud servers.
You can check this from the PHP Manager in your Site Tools after typing “memory_limit” in the filter under the PHP Variables section.
Edit the wp-config.php
To increase the WordPress memory limit, you need to edit your application’s wp-config.php file. You can do that from your hosting’s File Manager, via an FTP client after creating an FTP account or using an SSH connection.
As a rule, you should always back up your site files before editing them in case anything goes wrong.
If you want to edit the wp-config.php from your File Manager, navigate to the Site section of your Site Tools. You can usually find the file in the public_html folder, the default root directory for your WordPress installation. If you have changed your WordPress directory – the configuration file should be in that folder.
Right-click on the wp-config.php file to Edit it, paste the following code snippet inside, and Save the changes. Make sure you paste it right above the line /*That’s all, stop editing! Happy publishing*/.
define( 'WP_MEMORY_LIMIT', '512M' );
If you see the line “define( ‘WP_MEMORY_LIMIT’, ‘256M’ );”, simply edit the value to 512M.
Note that 512M (MB) is the plans’ optimal recommended memory limit. If you are on a Cloud plan, you can further customize the limit.
After saving the changes, clear your browser cache and refresh your website. The “Allowed Memory Size of Bytes Exhausted” error should be gone.
Check your php.ini file
The server checks the php.ini file before executing PHP scripts since it provides information regarding resource limits. This is not a core WordPress file; however, you might have it in your root folder if you have previously set other PHP variables. Therefore, you should ensure that the PHP memory value is not lower than the memory value defined in your wp-config.php. If that is the case, your WordPress won’t be able to actually use the 512 MB memory limit you set previously.
You can find the php.ini file in the public_html for your website and right-click on the file to Edit it. Look for the line defining the memory_limit variable and set the value accordingly.
memory_limit = 512M
Then, save the changes and reload your site to see if the PHP “Allowed Memory Size of Bytes Exhausted” error has been resolved.
Disable all plugins
If you have increased the memory limit, but your site is still showing the “Allowed memory size of bytes exhausted” PHP error – try disabling plugins. Most likely, a plugin on your site has exceeded the memory limit, causing a memory leak. Due to that faulty plugin, the browser shows the “Allowed memory size exhausted” error, preventing access to your website.
Therefore, by disabling your WordPress plugins, you should be able to access your site and start enabling them one by one to find the culprit.
SiteGround clients can easily disable WordPress plugins from their Site Tools > WordPress > Install & Manage.
By clicking the Disable all plugins button under the Actions menu and confirming, you will disable all your WordPress plugins at once.
Alternatively, you can disable all WordPress plugins directly from the database by following the steps in this article.
After that, log in to your WordPress Dashboard and start activating your plugins one by one. Eventually, you’ll activate the faulty plugin, and the “Allowed memory size of bytes exhausted” will appear. When that happens, you’ll have identified the plugin causing the error, and you should deactivate it again to restore access to your website.
What causes “Fatal Error: Allowed Memory Size of Bytes Exhausted” in WordPress?
WordPress code is written in PHP, a server-side programming language used to create dynamic web pages. This open-source code uses server resources to execute scripts and requests for multiple applications simultaneously. One of these resources is PHP memory which servers use to perform tasks successfully. For servers to operate correctly, system administrators allocate a certain amount of PHP memory per website.
Most web hosts set a default memory limit for WordPress, which may be a lower value than the allocated PHP Memory limit on the server. That leaves more “room” to increase your WordPress memory limit.
If a plugin or theme requires more memory than the default, you may run into a “PHP Fatal error: Allowed Memory Size of Bytes Exhausted.”
“Allowed Memory Size of Bytes Exhausted tried to allocate bytes” can also be caused by a faulty script on your WordPress.
Furthermore, older PHP versions (below PHP 5.3) use more memory; they are slower and more vulnerable to attacks. An old PHP version may be causing the “PHP allowed memory size of bytes exhausted” error. Thus, we recommend using the latest stable PHP version for your WordPress.
Note that your website may display the White Screen of Death; in this situation, you should enable the debug mode to see the actual error. If, after enabling it, your site shows a “Fatal error allowed memory size of bytes … exhausted tried to allocate … bytes,” – keep reading.
Summary
To wrap up, if you are struggling with WordPress’s fatal error “Allowed memory size of bytes exhausted tried to allocate bytes,” try increasing your memory limit. If that doesn’t work – disable your plugins to gain access to your site and start troubleshooting to find the culprit. In case the error is still present – feel free to contact our support team at any time.