Performance and monitoring

Adjust the WordPress memory limit

Reviewed on 3 min read WordPress memory

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.

Your account's PHP memory_limit

On our hosting, PHP's memory_limit is 128M by default. It is a setting, not a plan limit: you can change it to the value you need in two ways:

  • In cPanel, Select PHP Version, Options tab, memory_limit value.
  • In the website's .htaccess, with php_value memory_limit 256M.

Keep your plan's memory in mind: it is the maximum for all of the account's processes at once. If you raise memory_limit above what the account has free, PHP does not get more memory: processes are stopped when the account limit is reached.

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.