Fix: WordPress Memory Exhausted Error – Increase PHP Memory

Nothing‘s more frustrating than seeing your WordPress site grind to a halt with a “memory exhausted” error, my friend. But don’t worry – in this guide, I’ll show you how to quickly fix it by increasing PHP memory.

With my 15 years of experience as a webmaster, I’ve seen this issue many times. The good news is, it’s easily resolved! This article will give you all the details on diagnosing the problem and optimizing WordPress memory usage.

Understanding WordPress Memory Limits

Let‘s start with some background on PHP memory. WordPress is a PHP-based system that runs on web servers. These servers allocate a certain amount of memory for PHP scripts to use.

The default PHP memory limit is often only 32-64MB. But data shows the average WordPress site requires 96MB or more. See the problem?

Experts recommend a PHP memory limit of at least 128MB for WordPress. 256MB is ideal for sites with lots of plugins and images.

Why You‘re Getting the Memory Exhausted Error

There are a few common reasons your site may be exceeding the allocated PHP memory:

  • Too many plugins – especially inefficient, outdated ones
  • High resolution images in your media library
  • Inefficient code in themes/plugins
  • You‘ve outgrown your current hosting plan‘s resources

Over time, memory needs often grow without you realizing. Suddenly one day, boom – the dreaded "exhausted" error appears!

Fixing the Error by Increasing PHP Memory

Not to worry! There are a couple easy ways to increase PHP memory and stop the errors…

1. Increase Memory in wp-config.php

The best way is to edit WordPress‘s core config file wp-config.php. It‘s located in /public_html/ on your server.

Add this line before the "stop editing" comment:

define(‘WP_MEMORY_LIMIT‘, ‘256M‘);

This increases the memory to 256MB. Save changes and re-upload wp-config.php.

2. Increase Memory in .htaccess File

You can also raise the limit by editing the .htaccess file in WordPress‘s root folder:

php_value memory_limit 256M

Add this before the #END WordPress line. Save and upload .htaccess back to your server.

3. Increase Memory in php.ini (Advanced)

As a last resort, contact your host about increasing memory in php.ini. But be very careful editing this file yourself, as it can cause other issues.

Additional Tips to Optimize WordPress Memory

Increasing PHP memory is the fastest fix for the errors. But here are some optimization tips to reduce usage and prevent future issues:

Optimize Images

Large, unoptimized images are one of the biggest memory hogs. Here are a few tips:

  • Reduce image resolution if excessively large
  • Enable WordPress compression under Settings > Media
  • Install a compression plugin like EWWW Image Optimizer

Identify Problematic Plugins

Too many inefficient plugins can overload memory quickly. Try these steps:

  • Use P3 Plugin Profiler to identify poorly coded plugins
  • Remove inactive plugins you‘re no longer using
  • Avoid excessive plugins in general

Monitor Memory Over Time

Use a performance plugin like Query Monitor to keep an eye on memory usage. Look for spikes indicating an issue.

Debug Specific Causes

If errors recur, try switching to a default theme and selectively disabling plugins to isolate the culprit.

No More Frustrating Memory Errors!

Well my friend, I hope this detailed guide helps you stop those pesky "memory exhausted errors" for good. Optimizing WordPress performance doesn‘t have to be hard.

Let me know if you have any other questions! I‘m always happy to help out.

Written by Jason Striegel

C/C++, Java, Python, Linux developer for 18 years, A-Tech enthusiast love to share some useful tech hacks.