The “Allowed memory size of N bytes exhausted” error means a PHP request in WordPress needed more memory than its limit allowed. Fix it in order: find which limit applies (Site Health or the error log), raise WP_MEMORY_LIMIT within your host’s cap, then find the plugin, theme, or task using the memory so the error doesn’t return.
Most fixes in roundups of common WordPress errors stop at “add one line to wp-config.php.” That only helps if WordPress is the layer setting your limit. This guide shows how to tell which layer it is, raise the limit the right way for your server, and find what’s using the memory, including what changed on patched PHP versions in October 2026.
Before you change anything: take a full backup of your files and database. See our guide to automated daily backups. Make one change at a time and test on staging where you can. Every snippet below must be tested on staging (Apache module and PHP-FPM) before publishing.
Key Takeaways
- The error names a limit, not a culprit. The file and line in the message show where memory ran out, which is not always the code that used most of it.
- There are three layers of limits. WordPress constants (WP_MEMORY_LIMIT, WP_MAX_MEMORY_LIMIT), PHP’s memory_limit, and caps your host sets above both. WordPress can only raise the limit, never lower it, and only when the host allows it.
- Use the method that matches your server. wp-config.php works for WordPress’s own limit; .user.ini works only under CGI/FastCGI such as PHP-FPM; php_value in .htaccess works only when PHP runs as an Apache module.
- Raising the limit can hide the real problem. WordPress’s own documentation warns about this. Find the plugin, theme, or job using the memory, or move heavy work to cron.
- On patched PHP versions (8.5.12, 8.4.27, 8.3.36, 8.2.35 or later), there is also a hard limit. Crossing it ends the PHP process immediately with “Hard memory limit of N bytes exhausted”, and under PHP-FPM the visitor gets no response from PHP.
What the Error Message Actually Tells You

Reading “Allowed memory size of N bytes exhausted (tried to allocate X bytes)”
A typical message looks like this:
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /wp-content/plugins/example-plugin/includes/file.php on line 123
Two numbers matter:
- N (allowed memory size) is the limit in force for that request. Divide by 1,048,576 for megabytes: 134217728 bytes is 128 MB; 268435456 is 256 MB; 41943040 is 40 MB.
- X (tried to allocate) is the small chunk that tipped the request over.
The file and line show where PHP was when memory ran out. Treat it as a lead, not a verdict. Write N down: it tells you which layer set the limit and whether your changes take effect.
Where you’ll see it
On screen if errors are displayed; as “There has been a critical error on this website” (see our WordPress critical error guide); in wp-content/debug.log if WP_DEBUG_LOG is on; or in your host’s PHP error log.
New on patched PHP versions: “Hard memory limit of N bytes exhausted”
PHP’s 21 October 2026 security releases changed how the memory limit works. On patched PHP versions (8.5.12, 8.4.27, 8.3.36, 8.2.35 or later), memory_limit is a soft limit: an allocation that crosses it usually completes, and the usual fatal error is raised once PHP reaches a safe point. So you still see the familiar “Allowed memory size” error, but the process may briefly use more than the limit.
On those same patched PHP versions there is also a hard limit. By default it is twice memory_limit when memory_limit is 1G or less (for example, 256M for the default 128M), and memory_limit plus 1G above that. It is controlled by the new memory_hard_limit_percent directive. If a request would cross the hard limit, PHP ends the process immediately with exit status 137 and writes a line like this to standard error:
Hard memory limit of 268435456 bytes exhausted
That message isn’t written to the error_log (so it won’t appear in debug.log), and shutdown functions don’t run. Under PHP-FPM, the visitor gets no response from PHP, and you shouldn’t expect WordPress’s critical-error screen or recovery email. If you see blank responses and nothing in debug.log, ask your host to check PHP process logs for this line.
Step 1: Find Which Limit Is Actually Applied

The three layers
The limit in your error message comes from one of three layers. Changes only work at the layer that’s in control.
- WordPress constants. WP_MEMORY_LIMIT is the setting WordPress’s documentation ties to “Allowed memory size of xxxxxx bytes exhausted” messages. By default WordPress tries to raise memory to 40 MB on a single site and 64 MB on multisite, but it first checks whether PHP already has more and won’t lower it. In WordPress core, WordPress calls ini_set() only when WP_MEMORY_LIMIT is higher than the current PHP limit. If memory_limit can’t be changed at runtime, WP_MEMORY_LIMIT simply equals the current PHP limit.
- PHP’s memory_limit. PHP’s built-in default is “128M”, and it can be changed in many places (INI_ALL). A value of -1 means no limit.
- Host caps. A host can lock the value with php_admin_value, which .htaccess and ini_set() cannot override. On PHP 8.5 and later, a server-level max_memory_limit directive caps the highest value any script can set; asking for more produces a warning and the value is capped.
Check your PHP version and limits
- In WordPress: go to Tools > Site Health > Info. The Server section shows your PHP version. Look in the Server and WordPress Constants sections for the PHP memory limit and the WordPress memory constants. Confirm the exact labels on a current WordPress install before publishing.
- In your hosting panel: most panels show the PHP version and PHP settings for the site.
- Compare with the error. If N in the error matches the PHP limit shown, the PHP or host layer is in control. If N is 40 MB or 64 MB, WordPress’s default constant is probably the one being applied.
Why admin pages and image uploads behave differently
WordPress uses a second constant, WP_MAX_MEMORY_LIMIT, for heavier work. In core, if PHP’s memory_limit isn’t changeable (locked by the host), both WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT default to that PHP value. Otherwise WP_MAX_MEMORY_LIMIT defaults to 256M, unless PHP is already unlimited (-1) or set above 256M (WordPress keeps the PHP value), or unless WP_MEMORY_LIMIT itself is above 256M (then WP_MAX_MEMORY_LIMIT uses that WP_MEMORY_LIMIT value).
wp_raise_memory_limit() raises memory (never lowers it) for the ‘admin’, ‘image’, and ‘cron’ contexts. That’s why a site can load fine on the front end but fail during a wp-admin update, an image upload, or a scheduled task: those requests may run under a different limit, and N will reflect it.
Step 2: Raise the Limit the Right Way for Your Server

Match the method to how PHP runs on your server. If you don’t know, ask your host whether it’s an Apache module or PHP-FPM/FastCGI.
wp-config.php (WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT)
This is the WordPress-level setting. Add the lines above the line that loads wp-settings.php (usually above /* That’s all, stop editing! */). WordPress’s documentation gives these examples:
define( ‘WP_MEMORY_LIMIT’, ’96M’ );
define( ‘WP_MAX_MEMORY_LIMIT’, ‘128M’ );
Use the smallest increase that stops the error. These values only work up to what the PHP and host layers allow, and a number below your current PHP limit does nothing.
php.ini or your host’s control panel
If you can edit php.ini or your host offers a PHP settings screen, memory_limit can be changed there. This changes the PHP layer for the site, not just WordPress. Some hosts restrict which values you can choose.
.user.ini on PHP-FPM / FastCGI
Under CGI/FastCGI (including PHP-FPM), PHP reads per-directory .user.ini files:
memory_limit = 256M
Two cautions from the PHP manual. First, .user.ini files are read only under CGI/FastCGI; under an Apache module they are ignored. Second, they are cached for user_ini.cache_ttl, which defaults to 300 seconds, so a change can take up to 5 minutes to apply. Wait before deciding it didn’t work. Use a value appropriate for the site; the 256M shown is a format example, not a recommendation.
.htaccess php_value on Apache-module PHP only
When PHP runs as an Apache module and the server allows overrides (AllowOverride Options or AllowOverride All), you can set the value in .htaccess:
php_value memory_limit 256M
Use a value appropriate for the site; the 256M shown is a format example, not a recommendation. On servers running PHP-FPM or another FastCGI setup, this line isn’t understood and can take the whole site down with a 500 internal server error. If that happens, remove the line.
When the host’s cap wins, ask your host
If N doesn’t change after a correct edit, a higher layer is probably locking it (php_admin_value, or max_memory_limit on PHP 8.5+), and nothing in WordPress, .htaccess, or ini_set() can override it. Ask your host where the limit is set and whether it can be raised. If your site regularly needs more than your plan allows, review hosting and performance optimization before buying more memory.
| Method | Works when | Doesn’t work when | Source |
|---|---|---|---|
| WP_MEMORY_LIMIT / WP_MAX_MEMORY_LIMIT in wp-config.php | PHP lets WordPress raise memory_limit at runtime; placed before wp-settings.php | The host has locked memory_limit, or the value is above the host’s cap | WordPress wp-config docs; default-constants.php |
| php.ini / host PHP settings | You have access to the PHP configuration for the site | The host’s server-level settings override it | PHP Manual (core directives) |
| .user.ini | PHP runs as CGI/FastCGI (e.g. PHP-FPM) | PHP runs as an Apache module; or you check before the cache (default 300 s) expires | PHP Manual (.user.ini) |
| .htaccess php_value | PHP runs as an Apache module with AllowOverride Options or All | PHP runs under FPM/FastCGI (can cause a 500 error) | PHP Manual (configuration changes) |
| Ask the host | Always | — | WordPress wp-config docs; PHP Manual |
Step 3: Find What’s Using the Memory

WordPress’s documentation warns that raising the memory limit can hide the root of the problem until it comes back as you add plugins or features. If you still run out of memory after a reasonable increase, debug the site.
Turn on WP_DEBUG_LOG on staging
On a staging copy, enable debug logging in wp-config.php:
define( ‘WP_DEBUG’, true );
define( ‘WP_DEBUG_LOG’, true );
define( ‘WP_DEBUG_DISPLAY’, false );
Errors go to wp-content/debug.log. WordPress doesn’t recommend debug mode on live sites. Reproduce the error, look for the memory message and nearby plugin or theme paths, then turn debugging off and delete the log.
Deactivate plugins and switch themes to isolate
Isolation is the same process you’d use for a blank page: deactivate plugins (or rename the plugins folder over SFTP), switch to a default theme, and re-enable one at a time until the error returns. We cover the steps in our WordPress white screen of death guide, so we won’t repeat them here. If the error appears only after an update, check plugin and theme compatibility next.
Common heavy tasks
Imports, image uploads and regeneration, page builder editors, backup and migration plugins, and WooCommerce reports or exports use far more memory than a normal page view. If the error appears only during one of these, you’ve likely found the cause, and smaller batches or a different schedule may fix it without a bigger limit.
Move heavy jobs to cron
WordPress’s documentation says that if you still run out of memory with a higher limit, you may have too many memory-intensive functions tied to one action, and those should move to a cron job: scheduled, batched processing instead of one huge request triggered by a click.
Symptom → Likely Cause → Fix

| Symptom | Likely cause | Fix |
|---|---|---|
| Error says 41943040 bytes (40 MB) or 67108864 bytes (64 MB) | WordPress’s default WP_MEMORY_LIMIT is being applied because PHP’s own limit is lower | Set WP_MEMORY_LIMIT in wp-config.php within your host’s cap |
| Error only in wp-admin, during updates, or on image uploads | Heavier admin or image context (WP_MAX_MEMORY_LIMIT, wp_raise_memory_limit) | Check what task triggers it; adjust WP_MAX_MEMORY_LIMIT within the host cap; reduce the job size |
| N doesn’t change after editing wp-config.php | memory_limit can’t be changed at runtime, or a host cap (php_admin_value, max_memory_limit) applies | Ask your host where the limit is set and whether it can be raised |
| 500 error right after editing .htaccess | php_value used where PHP isn’t an Apache module | Remove the line; use .user.ini or the host panel |
| .user.ini change seems ignored | Cache not expired (default 300 s), or PHP isn’t running as CGI/FastCGI | Wait 5 minutes; confirm how PHP runs |
| Blank response or gateway error, nothing in debug.log | On patched PHP versions, the hard memory limit was hit and the process was killed | Ask the host to check PHP process logs for “Hard memory limit”; find the memory-heavy job |
| Error returns weeks after raising the limit | A plugin, theme, or task keeps growing its memory use | Isolate on staging; update or replace the component; move heavy work to cron |
| Error only during imports, backups, or reports | One oversized request | Batch the job, run it off-peak, or schedule it with cron |
Memory Error vs. the PHP2Shell Vulnerability: Not the Same Thing
An ordinary memory exhausted error is a resource problem: a request needed more memory than allowed. The PHP2Shell vulnerability is a security flaw fixed in the 21 October 2026 PHP releases (CVE-2026-109618 and CVE-2026-109619). One of its interim mitigations for servers that can’t update yet is setting memory_limit=-1 with php_admin_value. That is a temporary security workaround from the PHP advisory, not a fix for memory errors, and the advisory itself says only updating is a complete solution. Don’t set -1 to make a memory error go away.
Prevention Checklist
- Record your PHP version, PHP memory limit, and WordPress memory constants from Site Health.
- Stay on a patched PHP version (8.5.12, 8.4.27, 8.3.36, 8.2.35 or later).
- Remove unused plugins and keep the rest updated (plugin and theme maintenance).
- Test updates, imports, and theme changes on staging first.
- Batch imports, exports, and backups, or schedule them.
- Watch uptime and error logs (performance monitoring tools).
- Confirm your last backup restores before big changes.
Example: Hypothetical WooCommerce Import That Hits the Limit
This is a hypothetical example to illustrate the process. It is not a client case, and the numbers are for illustration only.
A store owner runs a large product CSV import from wp-admin. Partway through, the import stops with:
Allowed memory size of 268435456 bytes exhausted (tried to allocate 65536 bytes)
268435456 bytes is 256 MB. Site Health shows that 256M is the host’s PHP memory_limit, not WordPress’s own default constant. The owner adds a higher WP_MEMORY_LIMIT to wp-config.php, retries, and gets the same 256 MB error because WordPress cannot raise memory above the PHP/host cap.
That points above WordPress. The host confirms the plan’s PHP memory limit is fixed at the server level. Rather than upgrade for a one-off job, the owner splits the CSV into smaller files and imports them on staging first; each finishes under the existing limit. Batching goes into their WooCommerce maintenance routine. The lesson: when N doesn’t move, find out which layer is in control.
When Should You Contact a Developer?
Get help if you can’t reach wp-admin and aren’t comfortable editing files over SFTP; the error persists or returns after a reasonable increase; you suspect the hard limit on a patched PHP version; isolation points to a custom plugin or theme; or your host says the limit is fixed and you need to choose between optimizing the site and changing plans.
Keep Your Site Running Without Firefighting
Memory errors often appear when updates, plugins, and traffic collide. Our website maintenance plans include monitoring and updates, so problems like this get caught before they become downtime. If you’re dealing with one now, contact us and we’ll take a look.
FAQs
What does “Allowed memory size of N bytes exhausted” mean in WordPress?
It means one PHP request used all the memory its limit allowed and needed more. N is the limit in bytes; divide by 1,048,576 to get megabytes. The file and line show where memory ran out, which isn’t always the code that used most of it. Find which limit applied, raise it carefully, then find the cause.
How much memory does WordPress need?
WordPress doesn’t set one required number. By default it tries to raise PHP memory to 40 MB on single sites and 64 MB on multisite, and its admin limit defaults to 256M. PHP’s own default is 128M. Your plugins, theme, and tasks decide what your site actually needs, so raise the limit only as far as the error requires.
Why didn’t changing WP_MEMORY_LIMIT fix the error?
WordPress can only raise the PHP limit when PHP allows it. If your host locks memory_limit with php_admin_value, or caps it with max_memory_limit on PHP 8.5+, wp-config.php can’t go higher. The constant also has no effect if PHP already has more memory. Check whether N changed, then ask your host.
Is it safe to set memory_limit to -1?
Not as a routine fix. A value of -1 removes PHP’s memory limit, so one runaway request can use as much memory as the server will give it. The PHP advisory mentions -1 only as a temporary security workaround for servers that can’t update yet. For memory errors, raise the limit modestly and fix the cause.
What is the “Hard memory limit exhausted” message?
On patched PHP versions (8.5.12, 8.4.27, 8.3.36, 8.2.35 or later), a request that would cross the new hard limit is ended immediately. PHP writes “Hard memory limit of N bytes exhausted” to standard error, not the error log. Under PHP-FPM the visitor gets no response. By default the hard limit is twice memory_limit up to 1G.
Is the memory error related to the PHP2Shell vulnerability?
No. A memory exhausted error is a resource problem on your site. PHP2Shell is a security vulnerability fixed in the October 21, 2026 PHP releases. The two connect only because one interim mitigation in the PHP advisory involves memory settings. Update PHP for security, and troubleshoot memory errors separately using the steps in this guide.
Can a plugin cause memory exhausted errors?
Yes. A plugin or theme that loads too much data, or ties heavy work to a single request, can exhaust memory. WordPress’s documentation warns that raising the limit can hide that root cause until it returns. Isolate plugins on staging, check debug.log, and move heavy jobs to batched or scheduled processing.