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/orwp-content/themes/names the plugin or theme; a path inwp-includesmeans 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
| What you see | What it means | Fix 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 multisite | Define WP_MEMORY_LIMIT in wp-config.php |
Same 40 or 64 MB number after you set WP_MEMORY_LIMIT | The constant is placed too late in wp-config.php, misspelt, or PHP does not allow the value to be changed at runtime | Move 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 raised | Raise memory_limit in cPanel or php.ini |
268435456 bytes (256 MB) only in wp-admin, uploads or imports | The admin-side limit WP_MAX_MEMORY_LIMIT, which defaults to 256 MB | Resize the image or split the import first; raise WP_MAX_MEMORY_LIMIT only if needed |
| Error only in WP-CLI or a system cron job | The command line uses its own php.ini, separate from the web server's | Edit the CLI php.ini, or pass -d memory_limit=512M |
| "tried to allocate" a very large number | One operation asked for a huge block: a giant image, a runaway loop, a query loading every row | Find 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 RAM | Reduce PHP workers or add RAM; memory_limit is not the cause |
Hard memory limit of ... bytes exhausted in the PHP-FPM or server error output | On 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 log | Treat 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 log | Linux's out-of-memory killer stopped PHP or MySQL because the whole server ran out of RAM | Lower 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:
- 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.
- Test with plugins off. Note the active list first with
wp plugin list --status=active, runwp plugin deactivate --all, then reactivate them one at a time. Do this on a staging copy if the site takes orders. - 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.
- Check autoloaded options. WordPress loads every autoloaded row in
wp_optionson each request. A plugin that stores megabytes there makes every page heavier. - 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_onceline that loadswp-settings.phphas 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 -iin a terminal tells you about the CLI, not your website. - Forgetting to reload. PHP-FPM reads
php.iniwhen it starts, so reload the service after a change;.user.inichanges 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_DEBUGoff and deletedebug.logonce 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 )
- WordPress Developer Resources: Editing wp-config.php: Increasing memory allocated to PHP
- WordPress Developer Resources: wp_initial_constants() function reference
- WordPress Developer Resources: wp_raise_memory_limit() function reference
- WordPress Developer Resources: Debugging in WordPress
- PHP Manual: Description of core php.ini directives: memory_limit
- PHP Manual: .user.ini files
- PHP Manual: How to change configuration settings (php_value, php_admin_value)
- PHP Manual: FPM configuration
- cPanel: MultiPHP INI Editor for cPanel