Skip to content

Fix "Allowed memory size exhausted" on WordPress + cPanel

Read the PHP "Allowed memory size of N bytes exhausted" error on a cPanel-hosted WordPress site, raise memory_limit at the level that actually wins, and prove the failing request completes again.

“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_limit levels 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.

Ladder of the four memory_limit levels on cPanel, from the server php.ini to wp-config.php, with the PHP-FPM pool php_admin_value highlighted as the level that locks the value

  1. The server-wide php.ini of 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.
  2. 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, or php_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.ini and WP_MEMORY_LIMIT are ignored.
  3. 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 a php_value line in .htaccess; under suPHP it is a local php.ini named by suPHP_ConfigPath. cPanel » Software » MultiPHP INI Editor writes the right one for the handler.
  4. WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT in wp-config.php. WordPress calls ini_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

  1. Capture the exact line. CGI and suPHP write error_log in the document root, PHP-FPM writes ~/logs/<domain>.php.error.log, and WordPress writes wp-content/debug.log when WP_DEBUG_LOG is 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 3

    Example 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 118

    Here 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 --raw and wp config set WP_DEBUG_LOG true --raw, reproduce the error, then set both back to false.

  2. 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.php

    Example output:

    128M fpm-fcgi

    The second word is the handler as PHP sees it: fpm-fcgi is PHP-FPM, litespeed is LSAPI, cgi-fcgi is CGI or suPHP, apache2handler is 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.

  3. Check what wp-config.php declares. The constants are documented on the WordPress wp-config page.

    wp config get WP_MEMORY_LIMIT

    Example 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 512M

    Example 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.

  4. 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_limit to 256M, click Apply. Editor Mode shows the raw file instead. cPanel writes php.ini, .user.ini and, for DSO and suPHP, the .htaccess lines 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.ini

    Example output:

    memory_limit = 256M

    Rerun 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 with systemctl restart ea-php82-php-fpm.

  5. 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_value in the pool file.

    grep -n memory_limit /opt/cpanel/ea-php82/root/etc/php-fpm.d/example.com.conf

    Example output:

    31:php_admin_value[memory_limit] = 128M

    Do 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, so memory_limit goes 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.conf

    Example output:

    31:php_admin_value[memory_limit] = 512M

    An admin value stays locked, so a WP_MEMORY_LIMIT above 512M is still ignored, which is usually the intent. To let the account raise it, use php_value in both the key and the name field.

  6. Change the server-wide value (root) only when every account needs it. WHM » Software » MultiPHP INI Editor, Editor Mode, select ea-php82, change memory_limit, Save. That edits /opt/cpanel/ea-php82/root/etc/php.ini for 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-fpm

    Example output:

    409:memory_limit = 256M

    Keep this one modest: pm.max_children times memory_limit is the RAM you have promised to one pool, and every pool on the box adds up.

  7. 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 line part of the message. A path under wp-content/plugins/<name>/ names the plugin. A path under wp-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 --all

    Example 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. If command -v wp is 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 --yes

    Example 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.

Validate it works

Check from the handler inward.

  1. 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 lists WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT.

  2. From the version’s own binary. The command line reads the version php.ini only, not .user.ini or 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
  3. What WordPress ends up with. WP-CLI loads WordPress first, so this shows WP_MEMORY_LIMIT applied on top of the command-line value.

    wp eval 'echo ini_get("memory_limit"), PHP_EOL;'

    Example output:

    256M
  4. 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.log

    Example output:

    200
    3

    A 200 and a count that no longer climbs is the end state. A 500 with 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.ini saved, HTTP still reports the old value. Under PHP-FPM the file is cached for user_ini.cache_ttl, 300 seconds; wait or restart ea-php82-php-fpm. If it never changes, step 5 applies. Also check the location: PHP looks for .user.ini from the script’s directory up to the document root, so a file in public_html/blog/ covers only that subtree.

  • 500 Internal Server Error right after editing .htaccess. A bare php_value memory_limit 256M line is an Apache directive that exists only under mod_php (DSO). Under FPM, LSAPI or CGI, Apache answers 500 and logs Invalid command 'php_value' in /etc/apache2/logs/error_log. Remove the line and use .user.ini.

  • The log says Out of memory, not Allowed memory size. That is the operating system refusing memory, on CloudLinux usually the LVE PMEM cap. Check faults for the account:

    lveinfo --user=acme --period=1d --show-columns=From,To,mPMem,lPMem,PMemF

    Example output:

    +-------------+-------------+-------+-------+-------+
    |    From     |     To      | mPMem | lPMem | PMemF |
    +-------------+-------------+-------+-------+-------+
    | 10-25 13:45 | 10-26 13:45 | 1024  | 1024  | 7     |
    +-------------+-------------+-------+-------+-------+

    mPMem is the peak in MB, lPMem the cap, and a PMemF above 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 any memory_limit increase.

  • WP_MEMORY_LIMIT is set but Site Health still shows 128M. Either the define() sits below the stop-editing line, the pool locks the value, or a plugin calls ini_set('memory_limit') later. Find the latter with grep -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 outside memory_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 higher memory_limit worsens 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_log or debug.log is 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.