Spring Fresh Sale! - Up To 67% OFF BDIX Hosting + Free Domain
PHP

How to Fix the “Allowed Memory Size Exhausted” PHP Error

The "Allowed memory size of X bytes exhausted" error means a PHP script tried to use more memory than its limit permits, so PHP stopped it. The quick fix is to raise the limit; the lasting fix is to find why a script wanted so much memory in the first place.

The quick fix: raise the memory limit

You can increase PHP's memory limit yourself in cPanel — see increasing the PHP memory limit. You can also set it in your php.ini file or via PHP settings in cPanel. Moving from, say, 128M to 256M resolves most cases.

But don't just keep raising it

If a site needs ever-more memory, something is wrong. A raised limit is a sensible one-time bump, not a cure for a script that leaks memory. Look at what triggered it:

  • A heavy plugin or theme on WordPress — deactivate to test which one.
  • A large import or report processing too much at once — break it into smaller batches.
  • Inefficient code loading huge datasets into memory needlessly.

WordPress-specific note

WordPress has its own memory constant. Our guide on fixing the WordPress memory exhausted error covers setting it in wp-config.php and finding the plugin behind it.

Step-by-step

  1. Raise the PHP memory limit to a reasonable value (e.g. 256M).
  2. If the error returns, deactivate recent plugins one by one.
  3. Split large imports or exports into smaller pieces.
  4. Check the error log to see which file exhausted memory.

Frequently asked questions

How much should I set the memory limit to?

256M is comfortable for most sites; some heavier applications ask for 512M. Going far beyond that usually masks a real problem rather than solving it — investigate the cause instead.

I raised it and it still fails.

Then a specific script is consuming everything you give it. Find it in the error log, and address that script or plugin directly rather than raising the limit again.

Could this be caused by too little hosting memory?

On shared hosting your account has a memory ceiling. If your site legitimately needs more than the plan allows, that is a sign to consider a larger plan.

Was this article helpful?