“Allowed memory size of 134217728 bytes exhausted” is the fatal error PHP raises when one request on your cPanel-hosted WordPress site asks for more RAM than memory_limit, the per-request cap PHP enforces. The steps fit whoever runs that site, with only the cPanel login or with root on the server. The request dies on the spot: the visitor gets a blank page or the “There has been a critical error on this website” notice, and an upload or plugin update stops halfway. The fix is to raise memory_limit at the one level that wins for your PHP handler, confirm it over HTTP, and rule out a runaway plugin or image job as the real cause. You will finish with the failing request completing and a clear view of which of the four settings controls the limit.
What you’ll accomplish
- Read the bytes in the message as megabytes and know whether that is the limit you expected.
- Find which of the four
memory_limitlevels on cPanel controls your site, for your PHP handler. - Raise the limit at that level, from cPanel or from WHM, and see the new value reported over HTTP.
- Tell this fatal apart from a CloudLinux LVE kill, which looks similar and needs the opposite fix.
- Catch the plugin or image job eating the memory when raising the limit is the wrong answer.
Prerequisites
- A WordPress site on a cPanel account, with cPanel’s Terminal or SSH as the account user. WP-CLI, the WordPress command-line tool, available as
wp. - The domain’s PHP version, shown in cPanel » Software » MultiPHP Manager. Everything below uses PHP 8.2 as
ea-php82; swap in your version. - Root access to WHM (Web Host Manager, the server-wide side of cPanel) for the pool and server-wide steps only.
- CloudLinux is optional; the LVE checks apply only when the server runs it.
- A way to reproduce the failure, such as the page URL or the upload that throws the error.
How it works
PHP counts memory per request, not per server and not per site. Each request to WordPress runs in one PHP process, and memory_limit caps what that one process may allocate before PHP stops it. A site serving twenty 60 MB requests a second is fine under a 128M limit; one request that needs 130 MB fails every time.
The message carries three facts. Allowed memory size of 134217728 bytes is the limit in bytes; divide by 1,048,576 for megabytes, so 134217728 is 128M, 268435456 is 256M and 536870912 is 512M. tried to allocate 20480 bytes is the single allocation that did not fit, not the total the script wanted; a small number there means the request was already at the ceiling. in <file> on line <n> names the code that asked, often a core file called by the real culprit, so treat it as a lead.
Four settings can set memory_limit on a cPanel server, and they stack. The diagram shows which wins.
- The server-wide
php.iniof the PHP version, at/opt/cpanel/ea-php82/root/etc/php.ini, edited in WHM » Software » MultiPHP INI Editor. Every account on that version starts from this value. - The PHP-FPM pool of the domain. PHP-FPM (FastCGI Process Manager) is the PHP service behind the domain when its PHP-FPM switch is on. Its pool file can carry
php_value[memory_limit], which later levels may raise, orphp_admin_value[memory_limit], which nothing above it can change. This is the level most people miss: with an admin value in the pool,.user.iniandWP_MEMORY_LIMITare ignored. - The account’s own file in the document root. Under PHP-FPM, LSAPI (LiteSpeed’s own PHP interface) and CGI that file is
.user.ini, which PHP re-reads every 300 seconds by default. Under DSO (PHP loaded as an Apache module) it is aphp_valueline in.htaccess; under suPHP it is a localphp.ininamed bysuPHP_ConfigPath. cPanel » Software » MultiPHP INI Editor writes the right one for the handler. WP_MEMORY_LIMITandWP_MAX_MEMORY_LIMITinwp-config.php. WordPress callsini_set('memory_limit')while loading: 40M on the front end (64M on multisite) and 256M in wp-admin, cron and image editing by default. It only ever raises the value, never lowers it, and only where PHP lets the value change; a locked pool value wins over it.
In short, the last level allowed to speak wins, and a php_admin_value in the pool mutes everything after it. The handler decides whether a php_value line in .htaccess is honoured or breaks the site; MultiPHP INI Editor vs .htaccess shows how to tell.
CloudLinux adds a fifth wall that is not memory_limit. LVE (Lightweight Virtual Environment) caps the physical memory of all processes of an account together, as PMEM. When that cap is hit the operating system refuses the allocation. PHP then logs Out of memory (allocated N) (tried to allocate M bytes), or the process is killed and the visitor gets a 500 or 503. A 508 “Resource Limit Is Reached” page belongs to the same family, raised when the account’s entry-process cap is hit. If you see those, raising memory_limit makes things worse, since each request may then take a bigger share of the cap. The CloudLinux LVE limits guide explains each cap.
Step-by-step
-
Capture the exact line. CGI and suPHP write
error_login the document root, PHP-FPM writes~/logs/<domain>.php.error.log, and WordPress writeswp-content/debug.logwhenWP_DEBUG_LOGis on.grep -h 'Allowed memory size' ~/public_html/error_log ~/logs/*.php.error.log ~/public_html/wp-content/debug.log 2>/dev/null | tail -n 3Example output:
[26-Oct-2026 13:41:07 UTC] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /home/acme/public_html/wp-includes/class-wp-image-editor-gd.php on line 118Here the limit was 128M and GD, PHP’s built-in image library, ran out while building a thumbnail. If grep prints nothing, enable the log with
wp config set WP_DEBUG true --rawandwp config set WP_DEBUG_LOG true --raw, reproduce the error, then set both back tofalse. -
Ask PHP what the limit is, over HTTP. The command line can differ from the web handler, so test through the web server. Use a throwaway file under a random name and delete it right after.
echo '<?php echo ini_get("memory_limit"), " ", PHP_SAPI, PHP_EOL;' > ~/public_html/memchk-4k9q2.php curl -s https://example.com/memchk-4k9q2.php rm ~/public_html/memchk-4k9q2.phpExample output:
128M fpm-fcgiThe second word is the handler as PHP sees it:
fpm-fcgiis PHP-FPM,litespeedis LSAPI,cgi-fcgiis CGI or suPHP,apache2handleris DSO. That word decides which file matters in step 4. If the number is already 256M while the error names 128M, something lowers the limit after PHP starts; see Troubleshooting. -
Check what
wp-config.phpdeclares. The constants are documented on the WordPress wp-config page.wp config get WP_MEMORY_LIMITExample output:
Error: The constant or variable 'WP_MEMORY_LIMIT' is not defined in the 'wp-config.php' file.Not defined means the defaults apply, 40M on the front end and 256M in admin. Set both now; they take effect only if the pool does not lock the value.
wp config set WP_MEMORY_LIMIT 256M wp config set WP_MAX_MEMORY_LIMIT 512MExample output:
Success: Added the constant 'WP_MEMORY_LIMIT' to the 'wp-config.php' file with the value '256M'. Success: Added the constant 'WP_MAX_MEMORY_LIMIT' to the 'wp-config.php' file with the value '512M'.If you edit the file by hand, the two
define()lines must sit above the/* That's all, stop editing! */comment, or they run too late. -
Raise the account’s own limit in cPanel. Open cPanel » Software » MultiPHP INI Editor. Basic Mode lists the common directives with dropdowns: pick the domain’s document root, set
memory_limitto256M, click Apply. Editor Mode shows the raw file instead. cPanel writesphp.ini,.user.iniand, for DSO and suPHP, the.htaccesslines in that directory, so whichever handler is in use finds its value. From the shell, the same thing for PHP-FPM, LSAPI and CGI is one line:printf 'memory_limit = 256M\n' >> ~/public_html/.user.ini cat ~/public_html/.user.iniExample output:
memory_limit = 256MRerun step 2. Under PHP-FPM, expect the old value for up to 300 seconds, the default
user_ini.cache_ttl. Root can skip the wait withsystemctl restart ea-php82-php-fpm. -
If the value did not move, look for a lock in the PHP-FPM pool (root). Still 128M after the cache window means a
php_admin_valuein the pool file.grep -n memory_limit /opt/cpanel/ea-php82/root/etc/php-fpm.d/example.com.confExample output:
31:php_admin_value[memory_limit] = 128MDo not edit that file; cPanel regenerates it from the domain’s pool YAML,
/var/cpanel/userdata/acme/example.com.php-fpm.yaml. WHM » Software » MultiPHP Manager exposes only Max Children, Max Requests and Process Idle Timeout, somemory_limitgoes into the YAML by hand:--- _is_present: 1 pm_max_children: 5 pm_max_requests: 20 pm_process_idle_timeout: 10 php_admin_value_memory_limit: { name: 'php_admin_value[memory_limit]', value: 512M }Rebuild the pool files, which also restarts the FPM service, and read the generated file back:
/scripts/php_fpm_config --rebuild grep -n memory_limit /opt/cpanel/ea-php82/root/etc/php-fpm.d/example.com.confExample output:
31:php_admin_value[memory_limit] = 512MAn admin value stays locked, so a
WP_MEMORY_LIMITabove 512M is still ignored, which is usually the intent. To let the account raise it, usephp_valuein both the key and thenamefield. -
Change the server-wide value (root) only when every account needs it. WHM » Software » MultiPHP INI Editor, Editor Mode, select
ea-php82, changememory_limit, Save. That edits/opt/cpanel/ea-php82/root/etc/php.inifor every account on that version. Confirm it, then restart the version’s FPM service so running workers pick it up:grep -n '^memory_limit' /opt/cpanel/ea-php82/root/etc/php.ini systemctl restart ea-php82-php-fpmExample output:
409:memory_limit = 256MKeep this one modest:
pm.max_childrentimesmemory_limitis the RAM you have promised to one pool, and every pool on the box adds up. -
Decide whether raising was the right fix. A plain WordPress page fits inside the 40M default with room to spare. A request that needs 512M is doing something wrong, and a bigger limit only delays the next failure. Three ways to find the culprit:
- The
in ... on linepart of the message. A path underwp-content/plugins/<name>/names the plugin. A path underwp-includes/hides the caller; install Query Monitor, which shows peak memory per request in the admin bar, and open the failing page. - Halve the suspects with WP-CLI: record the active plugins, deactivate all, reproduce, then re-activate in groups until the error returns.
wp plugin list --status=active --field=name > ~/active-plugins.txt wp plugin deactivate --allExample output:
Plugin 'woocommerce' deactivated. Plugin 'wordfence' deactivated. Success: Deactivated 2 of 2 plugins.Re-activate with
wp plugin activate $(cat ~/active-plugins.txt)when done.- Image work. If the failing file is
class-wp-image-editor-gd.php, a large original is being resized inside the web request. Move that work to the command line and give only that process a big limit. Ifcommand -v wpis a shell wrapper, call the phar it points to.
/opt/cpanel/ea-php82/root/usr/bin/php -d memory_limit=1G "$(command -v wp)" media regenerate --yesExample output:
Found 312 images to regenerate. 1/312 Regenerated thumbnails for "hero-banner" (ID 2041). 2/312 Regenerated thumbnails for "team-photo" (ID 2040). Success: Regenerated 312 of 312 images.WordPress keeps the 1G, because it only ever raises
memory_limit. - The
Validate it works
Check from the handler inward.
-
Over HTTP, recreate the probe from step 2, fetch it, delete it. It must print the new value, for example
256M fpm-fcgi. Without a file, Tools » Site Health » Info » Server lists “PHP memory limit”, and the WordPress constants section listsWP_MEMORY_LIMITandWP_MAX_MEMORY_LIMIT. -
From the version’s own binary. The command line reads the version
php.inionly, not.user.inior the pool, so this proves step 6 alone./opt/cpanel/ea-php82/root/usr/bin/php -i | grep '^memory_limit'Example output:
memory_limit => 256M => 256M -
What WordPress ends up with. WP-CLI loads WordPress first, so this shows
WP_MEMORY_LIMITapplied on top of the command-line value.wp eval 'echo ini_get("memory_limit"), PHP_EOL;'Example output:
256M -
The request that failed. Reproduce it, then confirm the log stopped growing.
curl -s -o /dev/null -w '%{http_code}\n' https://example.com/shop/ grep -c 'Allowed memory size' ~/logs/example.com.php.error.logExample output:
200 3A
200and a count that no longer climbs is the end state. A500with a fresh log line means the limit is still not what you set; go back to step 2 and read the handler word again.
Troubleshooting
-
.user.inisaved, HTTP still reports the old value. Under PHP-FPM the file is cached foruser_ini.cache_ttl, 300 seconds; wait or restartea-php82-php-fpm. If it never changes, step 5 applies. Also check the location: PHP looks for.user.inifrom the script’s directory up to the document root, so a file inpublic_html/blog/covers only that subtree. -
500 Internal Server Error right after editing
.htaccess. A barephp_value memory_limit 256Mline is an Apache directive that exists only under mod_php (DSO). Under FPM, LSAPI or CGI, Apache answers 500 and logsInvalid command 'php_value'in/etc/apache2/logs/error_log. Remove the line and use.user.ini. -
The log says
Out of memory, notAllowed memory size. That is the operating system refusing memory, on CloudLinux usually the LVEPMEMcap. Check faults for the account:lveinfo --user=acme --period=1d --show-columns=From,To,mPMem,lPMem,PMemFExample output:
+-------------+-------------+-------+-------+-------+ | From | To | mPMem | lPMem | PMemF | +-------------+-------------+-------+-------+-------+ | 10-25 13:45 | 10-26 13:45 | 1024 | 1024 | 7 | +-------------+-------------+-------+-------+-------+mPMemis the peak in MB,lPMemthe cap, and aPMemFabove zero means the account hit its physical memory limit. Fix the consumer or raise the cap in the CloudLinux Manager plugin (WHM » Plugins), and undo anymemory_limitincrease. -
WP_MEMORY_LIMITis set but Site Health still shows 128M. Either thedefine()sits below the stop-editing line, the pool locks the value, or a plugin callsini_set('memory_limit')later. Find the latter withgrep -rn "ini_set" ~/public_html/wp-content --include=*.php | grep memory_limit. -
Only uploads of large photos fail, even at 256M. GD keeps the decoded image inside PHP’s memory, about 4 bytes per pixel. A 24-megapixel photo therefore needs roughly 100 MB before the first thumbnail. Install Imagick for the version in WHM » Software » EasyApache 4 (
ea-php82-php-imagick); WordPress prefers it, and its image buffers sit largely outsidememory_limit.
When this is the wrong approach
- The hungry request is a batch job, such as a product import or an export of a hundred thousand orders. Run it with WP-CLI or the plugin’s background mode, where a 1G limit for one process costs nothing, instead of giving every web request 1G.
- The number keeps climbing. A plugin update that doubled memory needs is a bug to roll back and report. Limits of 1G or more per request on a shared server are an outage waiting for traffic.
- The real error is
Out of memory, 503 or 508. That is the account cap, and a highermemory_limitworsens it. Fix the consumer, or move the account to a bigger LVE package. - There is no memory line in any log. A blank page with nothing in
error_logordebug.logis a different fault; start with the white screen of death guide. The cPanel documentation describes each MultiPHP screen above for your exact version.
Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.