PHP Fatal Error: Allowed Memory Size Exhausted

PHP Fatal Error: Allowed Memory Size Exhausted

Elena Rodriguez ·

Symptoms

You’re seeing a white screen or a raw PHP error that says something like Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 12345 bytes). Your WordPress site just hit its memory ceiling. PHP tried to use more RAM than it’s allowed, and the process died. The right way to fix this is to find what’s eating the memory — not just throw more RAM at it and hope for the best.

What Causes PHP Fatal Error: Allowed Memory Size Exhausted?

  1. Low PHP memory limit — Many shared hosts default to 64MB or even 32MB. That was fine in 2015. A modern WordPress site with WooCommerce and a page builder needs 256MB minimum.
  2. Bloated or poorly coded plugins — One badly written plugin can consume 50MB+ on every page load. Plugin conflicts make this worse.
  3. Theme loading too many assets — Themes that bundle dozens of features (sliders, portfolios, mega menus) whether you use them or not.
  4. Large image or CSV imports — Uploading hundreds of products or processing unoptimized images eats memory fast.
  5. PHP version mismatch — Running PHP 7.4 or older uses significantly more memory than PHP 8.1+. Upgrade if you haven’t.

How to Fix It

Step 1: Check Your Current Memory Limit

Before changing anything, find out what you’re working with. Add this to your theme’s functions.php temporarily or run it via WP-CLI:

wp eval "echo 'Memory limit: '. WP_MEMORY_LIMIT. PHP_EOL. 'Max: '. Ini_get('memory_limit');"

Or check Tools → Site Health → Info → Server in the WordPress dashboard. Look for the PHP memory limit row.

If it says 64M or lower, that’s almost certainly your problem.

Step 2: Increase the WordPress Memory Limit

Open wp-config.php in your site root via FTP, SSH, or your host’s file manager. Add these lines before the line that says /* That's all, stop editing! */:

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

WP_MEMORY_LIMIT controls the frontend. WP_MAX_MEMORY_LIMIT controls the admin dashboard, which typically needs more. Save the file and reload your site.

If this doesn’t work, your host may be overriding wp-config.php at the server level. Move to Step 3.

Step 3: Set the Limit in php.ini or.htaccess

Try editing your php.ini file (usually at /etc/php/8.x/fpm/php.ini or in your site root on shared hosting):

memory_limit = 256M

If you don’t have php.ini access, add this to your .htaccess file in the WordPress root:

php_value memory_limit 256M

On Nginx servers,.htaccess won’t work. You’ll need to edit the PHP-FPM pool config or ask your host to increase it. Kinsta, Cloudways, and WP Engine all let you adjust this from their dashboards — skip the file editing entirely.

Step 4: Find the Memory Hog

Throwing more RAM at the problem works, but it’s a bandage. The right way to fix this is to find what’s eating your memory. Enable WP_DEBUG to get a trail:

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

Check wp-content/debug.log for the full stack trace. It’ll tell you exactly which plugin or theme file triggered the fatal error.

Then deactivate plugins one by one to isolate the offender. WP-CLI makes this fast:

wp plugin deactivate --all
wp plugin activate plugin-name

Reactivate them one at a time. When the error returns, you’ve found your culprit.

Step 5: Deal With the Problem Plugin

Once you’ve identified the plugin:

  • Check for updates. Memory leaks often get patched. Run wp plugin update plugin-name.
  • Check alternatives. If a plugin consistently eats 80MB+, replace it. There’s almost always a leaner alternative.
  • Contact the developer. Share the debug.log stack trace. Good developers fix memory issues quickly.

Step 6: Upgrade PHP If You Haven’t

If you’re still on PHP 7.4, upgrade to PHP 8.2 or 8.3. The memory efficiency improvements alone can cut usage by 20-30%. Most managed hosts (Cloudways, Kinsta, SiteGround) let you switch PHP versions in one click.

# Check current PHP version
wp eval "echo phpversion();"

Prevention

  • Set WP_MEMORY_LIMIT to 256M from day one. Don’t wait for the crash. Add it to your wp-config.php right after installation.
  • Audit plugins quarterly. Use the Query Monitor plugin to see per-plugin memory usage. Anything over 20MB per request deserves scrutiny.
  • Optimize images before upload. Use ShortPixel or Imagify to compress images. A 5MB PNG uploaded 50 times during an import is 250MB of processing.
  • Use a managed WordPress host. Kinsta and Cloudways set generous memory limits by default and give you tools to monitor usage. Cheap shared hosting with 64MB limits will keep causing this error.

Last verified: April 2026