Performance and monitoring

Adjust the WordPress memory limit

Reviewed on 2 min read wordpress memoria

An Allowed memory size exhausted error means that a PHP run has reached its memory limit. Before raising it, find out which operation fails and which plugin, theme or process appears in the log.

Fatal error: Allowed memory size of ... bytes exhausted

Three different values

  • PHP's memory_limit: the effective memory limit for one run.
  • WordPress constants: values WordPress tries to request from PHP for certain tasks.
  • Hosting memory: the capacity shared by the account's processes; raising a constant does not upgrade the plan.

WordPress may try to raise the limit through PHP if the environment allows it. It is not necessarily tied to the initial value in php.ini, but it cannot exceed restrictions set by the service either. Check the effective value, not just what you have written in a file.

Edit wp-config.php

Save a copy outside the public root. Check whether the constants already exist and change their values without duplicating them. This example requests 128 MB for general use and 256 MB for contexts in which WordPress raises memory, such as certain admin tasks:

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

These are example values, not a universal recommendation. Place them before the final "stop editing" comment and before wp-settings.php is loaded. Do not add another PHP opening tag if the file is already inside a PHP block.

The WordPress configuration reference explains how it requests these changes. If PHP does not allow the change, check the configuration of the version that website uses.

Check and find the cause

Look at Tools > Site Health > Info and the server and constants data available. Reproduce the operation that was failing and check the log. The PHP in the terminal may have a different configuration from the website's.

If usage keeps growing, undo the setting and debug the component responsible on a test copy. Several requests with high limits can exhaust the hosting's combined memory. Do not use unlimited memory as a general fix for imports or runaway processes.

You may also find useful

Something wrong or out of date? Tell us and we will review it.