The error looks something like this:

Code
Fatal error: Allowed memory size of 134217728 bytes exhausted
(tried to allocate 20480 bytes) in /home/user/public_html/wp-content/plugins/xyz/file.php on line 120

The first number is the limit (128 MB in this example), and the second is the amount the script just tried to allocate. The file path tells you which plugin or theme is involved. Sometimes you see only a white screen or a 500 error instead of the message; for that case, see also common WordPress errors.

Why memory runs out#

Every request to WordPress is a PHP run, and each run has a limit. When a task gets heavy and crosses the limit, the server kills it. Common reasons:

  • A heavy plugin (page builder, backup, SEO, gallery) on a page with a lot of data.
  • Uploading or processing a very large image.
  • Importing or exporting a large file.
  • An infinite loop or query in theme or plugin code.
  • A very low host limit.

One important point: the error doesn't always mean "your site is weak". Sometimes a single operation, such as a full backup, an import of thousands of products or an upload of a multi-megabyte image, briefly needs a lot of memory. If the site runs fine the rest of the time, make that one task smaller or run it in batches, and don't raise the limit permanently for no reason. But if the error appears for no obvious reason during normal page views, look for a faulty plugin or theme.

Read the numbers#

The limit in the message is in bytes. A quick conversion for common values:

Bytes in the messageEquivalent
3355443232 MB
6710886464 MB
134217728128 MB
268435456256 MB

If the limit in the message is lower than what you wrote in wp-config, your setting was not applied and the host's PHP limit blocked it. To see the current limit, go to Site Health in the admin and open the server info; the PHP memory limit and the WordPress limit are listed there.

Step one: raise the limit#

There are three layers, and they must agree.

1. The WordPress setting#

In wp-config.php, above the line "That's all, stop editing":

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

WP_MEMORY_LIMIT applies to the public part of the site, and WP_MAX_MEMORY_LIMIT to the admin and heavy management tasks. The numbers are examples; try a lower value first.

2. PHP settings in the hosting panel#

In cPanel, raise memory_limit in the PHP version selector or the PHP settings editor (the exact name depends on the host). On a server you manage yourself, edit php.ini:

Code
memory_limit = 256M

After changing php.ini you may need to restart PHP or the web server.

3. The .htaccess file#

Some Apache hosts with the PHP module allow:

Apache
php_value memory_limit 256M

If the host runs PHP-FPM or FastCGI, this line causes a 500 error. In that case remove it immediately and use the second method. Always back up .htaccess before editing.

The final limit is set by the host. If the panel won't allow a higher value, talk to hosting support or upgrade your plan.

Step two: find the culprit#

Raising the limit often only hides the symptom. If usage goes past 256 MB, something is not working right.

  1. Look at the file named in the message. A path like plugins/plugin-name is a direct clue.
  2. Enable the error log: turn WP_DEBUG and WP_DEBUG_LOG on and WP_DEBUG_DISPLAY off so errors aren't printed to visitors. Then read wp-content/debug.log.
  3. If the error happens only on one particular page, check that page's content or related plugin.
  4. Deactivate plugins one by one; the full method is in fixing WordPress plugin conflicts.
  5. If the error appears only during an upload or a backup, shrink the file or run the backup in smaller parts.

Logging without displaying errors#

PHP
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );

Once you find the problem, turn WP_DEBUG off and delete the log file; it shouldn't stay on a live site forever.

If you're locked out of the admin#

Sometimes the error happens exactly when you can't reach the admin either. In that case, work from your host's file manager or FTP: first edit wp-config.php, and then, if needed, rename the suspect plugin's folder to deactivate it. Back up the file before any change.

Preventing it from coming back#

When the host won't let you change it#

On cheap shared hosting, the memory limit is usually locked by the provider and your setting is ignored. Two options remain: ask support to raise the limit to fit your site, or make the site lighter. If it is an online store or has high traffic, it may be time to upgrade. See the hosting tips in the shared hosting checklist.

Summary#

  • The message says a PHP run exceeded its memory limit; the file path in it points to the culprit.
  • Raise the limit consistently in wp-config.php (WP_MEMORY_LIMIT), the host's PHP settings and, if possible, .htaccess.
  • The real limit is set by the host; ask support.
  • The error log and deactivating plugins one by one will find the culprit.
  • Raising the limit is not a permanent fix; replace the heavy plugin or make the task smaller.