Talk to the NOC, IST hours — +91 75994 50220 support@bigdomainhost.com
Guide

How to fix "Allowed memory size exhausted" in WordPress

"Allowed memory size of ... bytes exhausted" is one of the most common PHP fatal errors on WordPress sites. This guide shows how to read the numbers in the message, raise the right limit in wp-config.php, cPanel or php.ini, and find the plugin or task that is really using the memory.

Short answer: The error means a PHP request hit its memory_limit, and the first number is that limit in bytes; fix it by adding define( 'WP_MEMORY_LIMIT', '256M' ); to wp-config.php. If the number does not change, raise memory_limit in cPanel's MultiPHP INI Editor or php.ini. If 256M still fails, find the plugin named in the error path.

What the error means

The full message usually looks like this, in wp-content/debug.log, the server error log, or on screen when errors are displayed:

PHP Fatal error:  Allowed memory size of 41943040 bytes exhausted (tried to allocate 20480 bytes) in /home/user/public_html/wp-content/plugins/some-plugin/includes/class-import.php on line 212

Every PHP request runs with a ceiling called memory_limit. The PHP manual describes it as the maximum amount of memory in bytes that a script may allocate, there to stop badly written code eating all the memory on a server. When a request goes over it, PHP stops with a fatal error. In WordPress that shows up as a blank page, "There has been a critical error on this website", a failed upload or a half-finished import.

The message holds three clues:

  • The first number is the limit that was in force, in bytes. 41943040 is 40 MB, 67108864 is 64 MB, 134217728 is 128 MB, 268435456 is 256 MB and 536870912 is 512 MB. PHP counts 1M as 1,048,576 bytes.
  • "tried to allocate" is the size of the one allocation that crossed the line, not the total the script needed. A small number means the request was creeping up to the limit; a huge one, such as several hundred megabytes in one go, usually points at a bug or an oversized file rather than a limit that is slightly too low.
  • The file path tells you what was running. A path under wp-content/plugins/ or wp-content/themes/ names the plugin or theme; a path in wp-includes means core was doing work for something else, so look at what you were doing at the time (uploading an image, importing, running a backup).

Quick diagnosis table

Memory error variants in WordPress and what each one means
What you seeWhat it meansFix first
Allowed memory size of 41943040 bytes (40 MB) or 67108864 (64 MB)WordPress's own default is in force: 40 MB on a single site, 64 MB on multisiteDefine WP_MEMORY_LIMIT in wp-config.php
Same 40 or 64 MB number after you set WP_MEMORY_LIMITThe constant is placed too late in wp-config.php, misspelt, or PHP does not allow the value to be changed at runtimeMove the line above the "stop editing" comment; check the host's cap
Allowed memory size of 134217728 bytes (128 MB)PHP's built-in default memory_limit, or a host-set value that WordPress has not raisedRaise memory_limit in cPanel or php.ini
268435456 bytes (256 MB) only in wp-admin, uploads or importsThe admin-side limit WP_MAX_MEMORY_LIMIT, which defaults to 256 MBResize the image or split the import first; raise WP_MAX_MEMORY_LIMIT only if needed
Error only in WP-CLI or a system cron jobThe command line uses its own php.ini, separate from the web server'sEdit the CLI php.ini, or pass -d memory_limit=512M
"tried to allocate" a very large numberOne operation asked for a huge block: a giant image, a runaway loop, a query loading every rowFind the code in the path; raising the limit rarely helps
Out of memory (allocated ...) without "Allowed memory size"Usually the process could not get memory from the operating system at all: the server or account is short of RAMReduce PHP workers or add RAM; memory_limit is not the cause
Hard memory limit of ... bytes exhausted in the PHP-FPM or server error outputOn PHP 8.2.35, 8.3.36, 8.4.27, 8.5.12 and later, memory_limit is a soft limit, and a request went past a separate hard limit (by default twice memory_limit, up to 1 GB over). PHP ends the process at once and the message bypasses the PHP error logTreat it like a very large "tried to allocate": find the code doing the work
No PHP error, but 502 or 503 errors and a "Killed process" line in the kernel logLinux's out-of-memory killer stopped PHP or MySQL because the whole server ran out of RAMLower pm.max_children or add RAM

Step 1: confirm the limit PHP is really using

Do not guess the current value; the number in the error is the most reliable reading. Two more ways to check:

  • In WordPress: go to Tools > Site Health > Info. The Server section lists the PHP settings the web server is using, and the WordPress Constants section shows the constants WordPress has loaded.
  • On a server you control: remember that the command line and the web server can load different files. On Ubuntu, check each one:
# the CLI's php.ini (used by WP-CLI and system cron)
php --ini
php -r 'echo ini_get("memory_limit"), PHP_EOL;'

# PHP-FPM's own settings (Ubuntu 24.04 ships PHP 8.3; 22.04 ships PHP 8.1)
php-fpm8.3 -i | grep -i memory_limit
grep -rn memory_limit /etc/php/8.3/fpm/php.ini /etc/php/8.3/fpm/pool.d/

On Ubuntu 22.04, replace 8.3 with 8.1. If you run Apache with mod_php instead of PHP-FPM, the web server's file is /etc/php/8.3/apache2/php.ini.

Step 2: turn on the debug log to find the culprit

If you only see "There has been a critical error", switch on logging so you can read the full message. Add these lines to wp-config.php, above the line that says /* That's all, stop editing! */:

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

WordPress then writes errors to wp-content/debug.log without showing them to visitors. Reproduce the problem, open the log and read the path in the memory error. When you have finished, set WP_DEBUG back to false and delete the log, because anyone who guesses its URL can download it. If the site will not load at all, our guide to the WordPress white screen of death covers recovery mode and disabling plugins without the dashboard.

Step 3: raise WP_MEMORY_LIMIT in wp-config.php

WordPress has its own memory setting on top of PHP's. By default WordPress tries to raise PHP's limit to 40 MB on a single site and 64 MB on multisite. It only ever raises the limit, never lowers it: if PHP already allows 128 MB, WordPress leaves it alone. To ask for more, add this to wp-config.php, above the "stop editing" line:

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

With WP-CLI over SSH, the same change is one command, run from the WordPress folder:

wp config set WP_MEMORY_LIMIT 256M

The dashboard, image processing and WP-Cron use a second constant, WP_MAX_MEMORY_LIMIT, which WordPress sets to 256 MB unless PHP already allows more. Raise it only if the error shows 268435456 bytes during admin work:

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

Both constants must be defined before wp-settings.php is loaded, which in a standard wp-config.php means above the "stop editing" comment. 256M is a common starting point, including for WooCommerce stores. Use M or G as the unit: PHP accepts only K, M and G as shorthand, so write 256M, not 256MB.

This works only if PHP lets WordPress change the value at runtime. If the host has locked memory_limit, WordPress quietly uses the locked value and your constant does nothing. That is when you change PHP's own setting.

Step 4: raise PHP's memory_limit

On cPanel hosting

cPanel's MultiPHP INI Editor (in the Software section) edits PHP settings per domain or for the whole account. In Basic Mode, pick the domain, set memory_limit to 256M and click Apply. cPanel writes the value into the files PHP reads for that site, which can include php.ini, .user.ini and .htaccess. Some hosts offer a different PHP options screen instead, often next to the PHP version selector; the setting has the same name.

On Bigdomainhost cPanel hosting and WordPress hosting, the PHP version and extensions are chosen per domain from the panel. If a value you set does not take effect, message us and we will check what is capping it.

With .user.ini (shared hosting without a settings screen)

When PHP runs as CGI or FastCGI, which includes PHP-FPM, PHP also reads a file called .user.ini in the site's folders. Create it in the WordPress root (next to wp-config.php) with one line:

memory_limit = 256M

PHP re-reads these files every 300 seconds by default (user_ini.cache_ttl), so wait up to five minutes before testing.

With .htaccess (Apache mod_php or LiteSpeed)

When PHP runs as an Apache module, or under LiteSpeed's LSAPI, a line in .htaccess works:

php_value memory_limit 256M

Do not add it on a server where Apache hands PHP to PHP-FPM: Apache does not recognise php_value there and the whole site can fail with a 500 Internal Server Error. If that happens, delete the line.

On your own Ubuntu server (PHP-FPM)

For Nginx or Apache with PHP-FPM on Ubuntu 24.04, edit the FPM php.ini, test the configuration and reload the service:

sudo sed -i.bak 's/^memory_limit = .*/memory_limit = 256M/' /etc/php/8.3/fpm/php.ini
sudo php-fpm8.3 -t
sudo systemctl reload php8.3-fpm

The .bak suffix keeps a copy of the original file. On Ubuntu 22.04, use /etc/php/8.1/fpm/php.ini, php-fpm8.1 and php8.1-fpm. If you run several sites, you can instead set the limit per pool, for example in /etc/php/8.3/fpm/pool.d/www.conf:

php_admin_value[memory_limit] = 256M

A value set with php_admin_value cannot be overridden by ini_set(), so WordPress's constants cannot raise it further. That makes it a useful hard cap on a server that hosts several sites, and a common reason a WP_MEMORY_LIMIT change "does nothing". PHP 8.5 adds another startup-only cap, max_memory_limit; if it is set, a higher memory_limit is cut down to it with a warning.

For WP-CLI and system cron, edit /etc/php/8.3/cli/php.ini, or raise the limit for one command (this form works when wp is the standard wp-cli.phar install; --skip-delete keeps the existing thumbnails):

php -d memory_limit=512M "$(command -v wp)" media regenerate --skip-delete --yes

On Windows (local XAMPP, WAMP or IIS)

Run php --ini in PowerShell or Command Prompt to see which php.ini the command line loads. The web server can load a different copy, so check the "Loaded Configuration File" line on a phpinfo() page as well. Edit memory_limit in that file, then restart Apache from the XAMPP or WAMP control panel, or run iisreset from an administrator prompt for IIS. Remove the phpinfo() page afterwards.

Step 5: if raising the limit does not fix it

The WordPress documentation itself warns that raising the memory limit can hide the real problem until it comes back. If a site still runs out at 256 MB or 512 MB, find what is using the memory:

  1. Read the path in the error. If the same plugin appears every time, update it, check its support forum or replace it. Our guide to a WordPress plugin not working walks through testing plugins one by one.
  2. Test with plugins off. Note the active list first with wp plugin list --status=active, run wp plugin deactivate --all, then reactivate them one at a time. Do this on a staging copy if the site takes orders.
  3. Look at the task, not just the page. Large image uploads, imports, backups, page-builder saves and thumbnail regeneration are the usual heavy moments. Resize photos before upload, split big imports, and run backups when traffic is low.
  4. Check autoloaded options. WordPress loads every autoloaded row in wp_options on each request. A plugin that stores megabytes there makes every page heavier.
  5. Measure. On a staging copy, log PHP's memory_get_peak_usage(true) at the end of a request to see the most memory it used.

When the server, not PHP, is out of memory

memory_limit applies to each request separately. Ten PHP-FPM workers each allowed 256 MB can, in the worst case, use about 2.5 GB between them, on top of MySQL and the web server. If that adds up to more than the server's RAM, Linux starts killing processes and visitors get 502 Bad Gateway errors instead of a PHP message. Check with:

free -h
sudo dmesg -T | grep -i -E 'killed process|out of memory'
sudo journalctl -k --since "1 hour ago" | grep -i oom

The fix is the opposite of raising the limit: lower pm.max_children in the FPM pool so that the number of workers multiplied by the memory each one uses fits in RAM, add swap as a buffer, or move to a larger plan. Our guide on how much RAM a VPS needs covers sizing for WordPress.

Common mistakes

  • Adding the define at the end of the file. Once the require_once line that loads wp-settings.php has run, the constant comes too late. Keep it above the "stop editing" comment.
  • Writing 256MB. PHP's shorthand is K, M or G only.
  • Editing the wrong php.ini. On Ubuntu the CLI, PHP-FPM and Apache mod_php each read their own file. php -i in a terminal tells you about the CLI, not your website.
  • Forgetting to reload. PHP-FPM reads php.ini when it starts, so reload the service after a change; .user.ini changes can take five minutes.
  • Setting memory_limit = -1. It removes the limit entirely, so one runaway request can take the whole server down with it. Use a number.
  • Raising the number every time it fails. If 512 MB is not enough for a normal page load, something is wrong with a plugin, theme or the data, and more memory only postpones it.
  • Leaving debug logging on. Turn WP_DEBUG off and delete debug.log once you have the answer.

If you cannot tell which limit is biting, send us the full error line on WhatsApp at +91 75994 50220 at any time, call during IST working hours, or write to support@bigdomainhost.com, and we will tell you which setting to change. Moving a site to us is free on every plan.

This guide was written by the Bigdomainhost team with AI assistance; facts were checked against the linked WordPress, PHP and cPanel documentation on 28 November 2026.

Sources (checked )

Answers

Frequently asked questions

Still unsure? Call +91 75994 50220 or write to support@bigdomainhost.com — a human replies in IST hours.

What does "Allowed memory size of 134217728 bytes exhausted" mean?

It means a PHP request used up its memory_limit and was stopped. The number is the limit in bytes: 134217728 is 128 MB, 268435456 is 256 MB and 41943040 is 40 MB. The "tried to allocate" figure is only the last allocation that crossed the line, not the total the script needed.

How do I increase the WordPress memory limit?

Add define( 'WP_MEMORY_LIMIT', '256M' ); to wp-config.php above the line that says "That's all, stop editing". WordPress then raises PHP's limit for its own requests. If the error still shows the old number, the host has locked PHP's memory_limit, and you need to raise it in cPanel, .user.ini or php.ini.

What is the difference between WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT?

WP_MEMORY_LIMIT applies to normal page loads and defaults to 40 MB on a single site and 64 MB on multisite. WP_MAX_MEMORY_LIMIT applies to the dashboard, image processing and WP-Cron, and defaults to 256 MB unless PHP already allows more. WordPress only ever raises PHP's limit with these, never lowers it.

How do I increase the PHP memory limit in cPanel?

Open MultiPHP INI Editor in the Software section, choose your domain in Basic Mode, set memory_limit to 256M and click Apply. Some hosts provide a different PHP options screen next to the PHP version selector instead. If the value you need is not allowed, ask your host to raise the cap.

Why did increasing WP_MEMORY_LIMIT not work?

The usual reasons are that the define sits below the "stop editing" comment, the value is written as 256MB instead of 256M, or the host sets memory_limit with php_admin_value or a similar lock that WordPress cannot override. Check the number in the new error: if it has not changed, the setting was not applied.

How much PHP memory does WordPress need?

WordPress's own default for a single site is 40 MB, and 256 MB is a common setting for sites with page builders or WooCommerce. If a normal page load needs more than 512 MB, treat it as a problem to find, usually a plugin, an oversized import or bloated autoloaded options, rather than a number to keep raising.

Is it safe to set memory_limit to -1?

No, not on a live site. -1 removes the limit entirely, so a single runaway request can use all the server's RAM and take other sites and the database down with it. Set a specific value such as 256M or 512M instead.

What is the difference between "Allowed memory size exhausted" and "Out of memory"?

"Allowed memory size exhausted" means PHP stopped a request at its configured memory_limit. "Out of memory" without that wording means the process could not get memory from the operating system, because the server or account itself is short of RAM. Raising memory_limit will not fix the second; reducing PHP workers or adding RAM will.

Support that picks up the phone.

In IST hours, in Hindi or English, and WhatsApp replies fastest at any time. Sales, migration and emergencies all reach the same engineers. No offshore queue, no 48-hour first reply.

Need cPanel or WHM with the ports already sorted?

Web & cPanel hosting comes with cPanel ready to log in to, reseller hosting adds white-label WHM, and a KVM VPS can have cPanel & WHM pre-installed. Call +91 75994 50220 or email support@bigdomainhost.com.