HiBlog WordPress

Fix the Allowed Memory Size Exhausted Error (PHP Memory Limit) in WordPress

  • Mina SeyfollahiAuthor
  • Last updated
  • 7 minutesReading time
  • 2,003Views
  • Mina Seyfollahi
  • Last updated:
  • 7 min read
  • 2,003 views
Fix the Allowed Memory Size Exhausted Error (PHP Memory Limit) in WordPress

You import a new theme’s demo, or turn on a page builder plugin, and suddenly your site shows this message instead of the page: Fatal error: Allowed memory size of 268435456 bytes exhausted. Or, on newer WordPress versions, just one sentence: “There has been a critical error on this website.” Don’t worry; the site isn’t broken, PHP just didn’t have enough memory for the job!

In this guide we explain what exactly this error means, how to raise the PHP memory limit in wp-config.php, cPanel, DirectAdmin and on a VPS, and how to find the plugin that eats the memory so the error doesn’t come back.

Short answer: this error means a PHP script has hit the memory limit set for it. On cPanel hosting, set memory_limit to 256M or 512M in MultiPHP INI Editor or Select PHP Version, and also add define( 'WP_MEMORY_LIMIT', '256M' ); to wp-config.php. Then deactivate the plugins one by one to see which one uses up the memory.

What does the Allowed memory size exhausted error mean?

WordPress runs on PHP, and the host sets a memory ceiling for every PHP run, called memory_limit. When a plugin, a theme or a task such as a demo import asks for more memory than this ceiling, PHP stops the job halfway and gives this error:

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes)
Allowed memory size exhausted error in WordPress

The first number is the current memory limit in bytes; divide it by 1048576 to get megabytes: 268435456 means 256 MB and 134217728 means 128 MB. If the current limit is very low (say 64 or 128 MB), raising it is usually enough; if it’s already 512 MB or more, the problem is a plugin or code that uses far too much memory.

Common signs of low memory

  • The message “There has been a critical error on this website.” or a white screen; in this case WordPress emails the site admin a description of the error with a link to recovery mode.
  • Installing or updating a plugin or theme stops halfway.
  • The dashboard or the page builder’s editor won’t open.
  • An image upload or a demo import stops in the middle.

If you have a white screen and no message, also see the guide to fixing the WordPress white screen.

Check the current memory limit

If the dashboard opens, go to Tools → Site Health and open the Info tab; in the Server section, the PHP memory limit value is the host’s memory_limit, and in the WordPress Constants section you’ll see WP_MEMORY_LIMIT.

Ways to increase the PHP memory limit in WordPress

1. In cPanel: MultiPHP INI Editor or Select PHP Version

On cPanel hosting, the best way is to change PHP’s own memory_limit. In the Software section of cPanel:

  • If the host runs CloudLinux: open Select PHP Version, go to the Options tab and set memory_limit to 256M or 512M. The change is saved right away.
  • Otherwise: open MultiPHP INI Editor, choose the domain, change memory_limit and click Apply.

You use the same two pages to raise the upload limit as well; we show it step by step with screenshots in increasing the PHP upload size in cPanel.

2. In the wp-config.php file

Open wp-config.php in the WordPress root folder with File Manager and put these two lines before the line /* That's all, stop editing! Happy publishing. */:

define( 'WP_MEMORY_LIMIT', '256M' );
define( 'WP_MAX_MEMORY_LIMIT', '512M' );

WP_MEMORY_LIMIT is the memory for the site’s pages, and WP_MAX_MEMORY_LIMIT the memory for the dashboard and its heavy tasks. One important point: WordPress can only raise the memory as far as the host allows. If PHP’s own memory_limit is locked at 128M, these lines alone won’t help; that’s why you should do the first method too.

3. In DirectAdmin

In DirectAdmin, click PHP Settings in the Account Manager section, choose the domain and change memory_limit. If you don’t see this option, ask your host’s support to raise the limit.

4. With the .htaccess file (only on some hosts)

php_value memory_limit 256M

This line only works when PHP runs as an Apache module. On most of today’s hosts, which use PHP-FPM, this very line takes the site down with a 500 error; if that happens, delete the line right away. See the guide to fixing the 500 error on hosting.

5. On a VPS: php.ini

On your own VPS, change memory_limit in the php.ini of the PHP version your site runs on. PHP-FPM has its own file, which on Ubuntu is something like /etc/php/8.3/fpm/php.ini; the php --ini command only shows the file of the command-line PHP:

memory_limit = 256M

Then restart the PHP-FPM service, for example sudo systemctl restart php8.3-fpm.

Finding the plugin that eats the memory

Raising the memory is first aid, not a cure. If the error comes back even with 512M, look for the culprit:

  1. Before anything else, back up the files and the database.
  2. In Plugins, deactivate the plugins one by one and check each time whether the error is gone. If the dashboard won’t open, temporarily rename the wp-content/plugins folder in File Manager so that all the plugins are deactivated.
  3. With the Query Monitor plugin, see how much memory each page uses and which plugins send heavy queries to the database.
  4. If needed, turn on error logging with define( 'WP_DEBUG', true ); and define( 'WP_DEBUG_LOG', true ); in wp-config.php; the errors are written to wp-content/debug.log. After troubleshooting, set both back to false.

Page builders with lots of add-ons, heavy sliders, demo importers and WooCommerce with dozens of extensions are the most common culprits. Also get rid of nulled plugins and plugins that are no longer updated; they eat memory and they’re a way in for attackers.

How much memory is enough?

Site typeSuggested memory_limit
A company site or a simple blog128M to 256M
A site with a page builder and many plugins256M
A WooCommerce store or a multilingual site512M

Much larger numbers, such as 1G, usually just hide the problem, and on shared hosting the service’s resource limits won’t allow them anyway.

How to keep the error from coming back

  • Use a PHP version that still gets security support, such as 8.3 or 8.4; newer versions are faster and handle memory better.
  • Set up page caching so most visits never reach PHP at all.
  • Delete unused plugins, don’t just deactivate them.
  • If the site has outgrown the hosting’s resource limits, it’s time to upgrade the service.

Frequently asked questions

I set WP_MEMORY_LIMIT but the error didn’t go away; why?

Because PHP’s own memory_limit is lower and the host doesn’t let WordPress raise it from inside. Raise the limit in cPanel’s MultiPHP INI Editor or Select PHP Version, DirectAdmin’s PHP Settings or the server’s php.ini.

Is raising the PHP memory limit risky?

Not with sensible numbers such as 256M and 512M. This number is a ceiling, not an amount that’s always reserved; only very large numbers can let a faulty piece of code use up the server’s resources.

How is memory_limit different from the hosting’s RAM?

memory_limit is the memory ceiling of each PHP run; the hosting’s RAM is the ceiling for the total memory of all the processes of your service. memory_limit can be high while the whole service runs out of RAM under heavy traffic; you can see this in cPanel’s Resource Usage section.

Hassle-free WordPress hosting

On HiData’s professional cPanel hosting you set the PHP version and memory_limit yourself in cPanel, and daily, weekly and monthly backups with free restores keep your experiments safe. For busy stores, high-traffic cPanel hosting has more resources. If you’re just launching your site, read the guide to creating a website.

Sources

Share Post

hidata.org/en/blog/fix-wordpress-memory-exhausted-error/
In Social Media

Add Comment

Related Articles