How to Fix the WordPress Memory Exhausted Error

WordPress memory reservoir expanded with additional RAM modules

The WordPress “memory exhausted” error means PHP hit the maximum amount of memory it is allowed to use for one request. You fix it by raising the limit to a sensible value and, if the error keeps returning, finding the plugin or task that needs so much memory.

The error looks like this:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /home/example/public_html/wp-content/plugins/some-plugin/file.php on line 123

The first number is the limit that was in force, in bytes. 134217728 bytes is 128 MB; 268435456 bytes is 256 MB. The file path shows where PHP ran out of memory. That file is not always the cause, but if it is inside a plugin folder, that plugin is the first thing to check.

Two Limits: PHP and WordPress

There are two settings involved, and confusing them is why many fixes do not work:

SettingSet byWhat it does
PHP memory_limitYour host (php.ini, .user.ini or the control panel)The hard maximum for any PHP request.
WP_MEMORY_LIMITYou, in wp-config.phpHow much memory WordPress asks for on normal pages. Defaults to 40 MB on a single site and 64 MB on Multisite.
WP_MAX_MEMORY_LIMITYou, in wp-config.phpHow much WordPress asks for in the admin and for heavy tasks such as image processing. Defaults to 256 MB.

WordPress can raise the PHP limit up to these values only if the host allows it. If your host caps PHP at 128 MB, setting WP_MEMORY_LIMIT to 512 MB changes nothing. That is why the first step is to check what you actually have.

Step 1: Check Your Current Limits

Go to Tools > Site Health > Info. Open the Server section to see the PHP memory limit, and the WordPress Constants section to see WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT. If you cannot reach the dashboard, ask your host or check the PHP settings in your control panel.

Step 2: Raise the WordPress Limit

Open wp-config.php in your site’s main folder with your host’s file manager or SFTP, and add these lines above the line that says “That’s all, stop editing”:

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

256 MB is enough for most sites, including many WooCommerce stores. Reload the page that showed the error. Keep a copy of the original wp-config.php so you can undo the change.

If you would rather not edit files, my free plugin Memory Limit Manager sets both values from a settings page. It backs up wp-config.php before each change and warns you if a theme or another plugin already defines the limits. It needs a writable wp-config.php, and like any WordPress setting it cannot go above the limit your host allows.

Step 3: Raise the PHP Limit If WordPress Cannot

If Site Health still shows a lower PHP memory limit, raise it where your host expects it:

  • Control panel: in cPanel, use MultiPHP INI Editor or Select PHP Version > Options and set memory_limit. Managed hosts usually have a PHP settings screen or will change it for you.
  • .user.ini file: on hosts that run PHP as PHP-FPM or CGI, create or edit .user.ini in the site’s main folder with memory_limit = 256M. Changes can take a few minutes to apply.
  • php.ini file: some hosts read a php.ini file in your folder; others ignore it. Check your host’s documentation before relying on it.

Avoid adding php_value memory_limit to .htaccess unless your host says it supports it. On servers that run PHP-FPM, that line causes a 500 Internal Server Error for the whole site.

Step 4: Find What Is Using So Much Memory

If the error comes back after raising the limit, or appears even at 256 MB, something is using far more memory than it should. Common causes:

  • A plugin that loads large amounts of data on every page, such as some page builders, statistics or related-posts plugins.
  • Imports, exports and backups that process the whole site in one request.
  • Very large images being resized after upload.
  • A plugin conflict or a loop that keeps allocating memory until it fails.

Check the file path in the error message, then test by deactivating the plugin it points to, ideally on a staging copy. Raising the limit further only hides a runaway process, and on shared hosting it can get your account throttled.

If the error stops you reaching the dashboard or keeps coming back, I can diagnose and fix it for you. Send me the exact error message and what you were doing when it appeared.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to our Monthly Newsletter

Get monthly updates of WordPress tips, tricks, and tutorials in your email.

Thanks. You have successfully subscribed.