Few WordPress errors look as alarming as this one: “Fatal error: Allowed memory size of 134217728 bytes exhausted.” It can appear on a white screen, in the middle of an image upload, during a plugin update or only on one admin page. Sometimes WordPress catches it and shows “There has been a critical error on this website” instead, so you may not even see the real message.
The good news is that the wordpress memory limit error is one of the most predictable problems in WordPress. Something asked PHP for more memory than it is allowed to use, and PHP stopped the script. Fixing it means answering two questions: how much memory is the site really allowed, and what is using it all? This guide shows how to read the message, how the three different limits work together, how to check and raise the limit correctly for your type of server and how to find the plugin, theme or task that is actually eating the memory.
What the Error Message Is Telling You
The full message usually looks like this: “Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /wp-content/plugins/example/file.php on line 512.” Each part is useful. The first number is the memory ceiling for this request, in bytes. The second number is the size of the single request for memory that pushed it over the edge. The file path is where PHP happened to be when it ran out.
To turn bytes into megabytes, divide by 1,048,576. The table below covers the values you will see most often.
| Bytes in the Error | Limit in Megabytes | Common Source |
|---|---|---|
| 33554432 | 32M | Very old or restricted hosting |
| 41943040 | 40M | WordPress default for single sites |
| 67108864 | 64M | WordPress default for multisite, many budget hosts |
| 134217728 | 128M | PHP default memory_limit |
| 268435456 | 256M | WordPress admin default, common host setting |
| 536870912 | 512M | Larger plans and store setups |
The “tried to allocate” number is a valuable clue. A small value, a few kilobytes, means the request grew steadily until it hit the ceiling, which is typical of a heavy page, too many plugins or a large query result. A huge value, such as tens or hundreds of megabytes in one go, means a single operation asked for a big block, which usually points to a large image, an export or an import. Keep the file path too. It does not always name the guilty code, but it is the best starting point you have.
The Three Limits That Decide How Much Memory WordPress Gets
Most guides treat the memory limit as a single setting. In reality, three values work together, and confusing them is why so many “I added the line and nothing changed” stories exist.
The first is PHP’s own memory_limit. The PHP core configuration documentation defines it as the maximum memory a single script may allocate, with a default of 128M and -1 meaning no limit. It is set by the host in php.ini, in the PHP-FPM pool configuration or in per-directory files. This is the hard ceiling. Nothing inside WordPress can be more generous than what the server allows.
The second is WP_MEMORY_LIMIT, the value WordPress tries to use for normal front-end requests. The wp-config.php documentation explains that WordPress tries to raise PHP memory to 40MB on single sites and 64MB on multisite by default, and that it only raises the limit when PHP’s current value is lower. If PHP already allows 256M, WordPress does not lower it to 40M.
The third is WP_MAX_MEMORY_LIMIT, a separate and higher value for heavier work. WordPress applies it in the admin area and for tasks such as image editing through the wp_raise_memory_limit function, with a default of 256M. This is why a site can work fine for visitors while an upload or admin screen fails, or the other way around.
All of this depends on one condition: the host must let PHP change its memory limit at runtime. WordPress raises the limit by calling ini_set. If the host has locked memory_limit, for example with php_admin_value in the PHP-FPM pool, those calls silently fail and both WordPress constants stop mattering. PHP’s own rules state that admin-level values cannot be overridden by scripts or .htaccess.
| Setting | Where It Is Set | Applies To | Default |
|---|---|---|---|
| memory_limit | php.ini, PHP-FPM pool, .user.ini, .htaccess on mod_php | Every PHP script, hard ceiling | 128M |
| WP_MEMORY_LIMIT | wp-config.php | WordPress front-end requests | 40M single site, 64M multisite |
| WP_MAX_MEMORY_LIMIT | wp-config.php | Admin, image processing and heavy tasks | 256M |
With the three limits in mind, the next step is to see what your site really has, rather than what you think you set.
Check Your Current Limit First
The quickest check is Site Health. Go to Tools, then Site Health, then the Info tab. The Server section shows the PHP memory limit, and the WordPress Constants section shows WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT. The Site Health screen documentation describes each section. Comparing these values tells you immediately whether your wp-config.php change was applied or capped by the server.
If the dashboard itself is down, use WP-CLI or a temporary file. With WP-CLI, `wp eval ‘echo ini_get(“memory_limit”), ” “, WP_MEMORY_LIMIT, ” “, WP_MAX_MEMORY_LIMIT;’` prints all three. Remember that the command line often uses a different php.ini than the web server, so the CLI value can differ from what visitors get. When you need the web value, a small PHP file that prints `ini_get(‘memory_limit’)`, uploaded for a minute and then deleted, gives the true answer.
Raising the Limit in wp-config.php
Once you know the current values, the simplest change is in wp-config.php. Add these lines above the comment that says “That’s all, stop editing!”, because the constants must be defined before wp-settings.php loads:
“`php
define( ‘WP_MEMORY_LIMIT’, ‘256M’ );
define( ‘WP_MAX_MEMORY_LIMIT’, ‘512M’ );
“`
Use straight quotes, keep a copy of the original file and check Site Health afterward. If the new values show up and the error is gone, you are done with this step. If the values show up in the WordPress Constants section but the PHP memory limit in the Server section is still lower, the server is capping you, and you need one of the methods in the next section.
When wp-config.php Is Not Enough: php.ini, .user.ini and PHP-FPM
The right server-level method depends on how PHP runs, and using the wrong one either does nothing or breaks the site. This is the part most guides gloss over, and it is where most failed fixes come from.
On older Apache setups where PHP runs as an Apache module, called mod_php, you can add `php_value memory_limit 256M` to .htaccess. On servers that run PHP through PHP-FPM or another FastCGI setup, which covers most modern hosting and every Nginx server, that same line causes a 500 Internal Server Error, because Apache does not understand the directive without the module. If you add it and the site goes down, remove the line first.
On FastCGI and PHP-FPM servers, the usual per-site option is a .user.ini file in the site’s root folder containing `memory_limit = 256M`. The PHP documentation for .user.ini files notes that PHP rereads these files on a timer set by user_ini.cache_ttl, which defaults to 300 seconds. Many people add the file, test immediately, see no change and give up. Wait five minutes before you test.
If you manage the server, the cleanest place is the PHP-FPM pool configuration. The PHP-FPM configuration reference shows that pool files accept php_value and php_admin_value settings. A php_admin_value memory_limit fixes the value so neither WordPress nor plugins can change it, which is predictable but means the WordPress constants have no effect. Reload PHP-FPM after the change.
| Server Setup | Method That Works | Watch Out For |
|---|---|---|
| Apache with mod_php | php_value in .htaccess, or php.ini | Rare on modern hosting |
| Apache or Nginx with PHP-FPM | .user.ini or pool configuration | .htaccess php_value causes a 500 error |
| Managed or control panel hosting | The host’s PHP settings screen | Plan-level caps you cannot exceed |
| WP-CLI on the command line | CLI php.ini, or php -d memory_limit=512M | Separate from the web server value |
If none of these options are available, ask your host directly what memory_limit your plan allows and how to change it. On shared hosting, the honest answer is sometimes that the plan cannot go higher, which is a sign the site has outgrown it.
Finding What Is Actually Using the Memory
Raising the limit is a valid fix when a site has simply grown. It is not a fix when one plugin has a memory leak, an import tries to load 100,000 rows at once or a loop never ends. In those cases a higher limit only delays the crash, and on a busy server it lets each runaway request take more of the memory that other visitors need. That is why the second half of the job is finding the cause.
Start with the logs. Turn on WordPress debug logging as described in Debugging in WordPress, with WP_DEBUG and WP_DEBUG_LOG set to true and WP_DEBUG_DISPLAY set to false, so errors go to wp-content/debug.log instead of the screen. Reproduce the error, then read the log. Repeated memory errors that always name the same plugin folder are a strong lead. Since WordPress 5.2, the site admin also gets a recovery mode email after a fatal error, which often names the plugin or theme involved and gives a link to log in with it paused.
Next, isolate. The reliable method looks like this:
- Reproduce the error on a specific page or action so you can test it again.
- Switch to a default theme on staging to rule the theme in or out.
- Deactivate plugins in halves, or rename the plugins folder over SFTP if the dashboard is down.
- Reactivate one at a time until the error returns, which identifies the culprit.
- Measure peak memory on the working pages to see how close they run to the limit.
For that last step, the Query Monitor plugin shows peak memory usage for each page, and PHP’s own memory_get_peak_usage function is what such tools rely on. If normal pages already use 90% of the limit, the site has grown and a higher limit is reasonable. If normal pages use a fraction of it and one action spikes, fix that action instead.
Do this testing on a WordPress staging site whenever you can, especially on stores, because deactivating plugins on live can break checkout or forms for real visitors.
Common Culprits and How to Fix Each
Once you know where the memory goes, the fix is usually clear. Most memory errors trace back to a short list of causes.
| Cause | Typical Sign | Better Fix Than a Higher Limit |
|---|---|---|
| Large image uploads | Error only when uploading or editing images | Resize images before upload, use WP_MAX_MEMORY_LIMIT for the admin |
| Imports and exports | Error partway through a CSV or XML job | Split the file, use WP-CLI or a batch-based importer |
| Page builders on long pages | Error only in the editor | Raise WP_MAX_MEMORY_LIMIT, split very long pages |
| Heavy or leaking plugin | Same plugin path in every error | Update it, report it or replace it |
| Huge autoloaded options | Every page close to the limit | Clean up wp_options and autoloaded data |
| Outdated PHP version | Errors after plugin updates | Move to a supported PHP version |
Images deserve a special note. To resize an image, PHP decodes it into raw pixels first, so a 6000 by 4000 pixel photo takes roughly 96 MB in memory at 4 bytes per pixel before any copies are made. That is why one phone photo can crash an upload on a site with a low limit. Database bloat appears in the table too, because heavy autoloaded options load on every request, so a database cleanup of wp_options can lower memory use on every page. If the problem started after updates on an old PHP version, see how to update the PHP version in WordPress safely.
How Much Memory Is Enough
There is no single right number, because memory needs depend on the plugins, theme and traffic of each site. A simple brochure site often runs comfortably on PHP’s default 128M, while stores, membership sites and heavy page builders usually need more. The honest way to choose is to measure peak usage on your busiest pages and set the limit with sensible headroom above it.
Higher is not always safer. The memory_limit setting applies per request, so on a server with limited RAM, a very high value lets a few runaway requests use memory that other visitors need, and the server may start failing in worse ways. Setting -1, which removes the limit entirely, is a bad idea on a live site for the same reason. Treat the limit as a guardrail that catches broken code, not just an obstacle.
How Webueno Handles WordPress Memory Limit Errors
At Webueno, memory errors fall under our troubleshooting service for PHP errors. We read the logs, find whether the limit or the code is the real problem, test fixes on staging and only then apply them to the live site. When a site has simply outgrown its setup, we tune the PHP configuration rather than just raising numbers.
Our WordPress hosting runs on DigitalOcean with one site per server, so another customer’s runaway script cannot take memory from your site. Each site can run its own PHP version, staging and live sit on the same server so tests match reality and migration is included when you move a site to us.
To catch problems early, uptime monitoring checks every 3 minutes and alerts after 3 failed pings, about 9 minutes, so a fatal error on the homepage does not go unnoticed for days. Maintenance plans cost $10 per site for Monthly, $20 for Weekly and $60 for Daily, with the Webueno Care Assistant plugin, a monthly automatic ticket, visual inspection and form checks. The Daily Backups add-on keeps daily offsite copies of files, database and configuration.
One-off fixes are billed in credits, where 1 credit equals 1 hour of work at $42, and bundles save up to 21%. Agencies get a white-label agency account and set their own margin, so fixing memory errors on client sites becomes part of their own service.
Fix the Limit, Then Fix the Cause
The memory error is PHP doing its job: stopping a request that wants more than it is allowed. Read the message, check all three limits in Site Health, raise them with the method that matches your server and verify the change. Then look at what is using the memory, because a plugin, import or oversized image is often the real problem.
If you would rather have someone else read the logs and find the cause, create your Webueno account and open a troubleshooting ticket for the site that is throwing the error.
Frequently Asked Questions
These are the questions we hear most often from site owners and agencies dealing with memory errors.
What Is the Default WordPress Memory Limit?
WordPress tries to set 40MB for single sites and 64MB for multisite, and 256MB for admin tasks through WP_MAX_MEMORY_LIMIT. If PHP already allows more, WordPress keeps the higher value, and PHP’s own default is 128MB.
Why Did Increasing WP_MEMORY_LIMIT Not Work?
Usually because the server’s PHP memory_limit is lower or locked. WordPress cannot go above the server ceiling. Check the PHP memory limit in Site Health and raise it through .user.ini, php.ini or your host’s settings.
How Do I Check My PHP Memory Limit in WordPress?
Open Tools, then Site Health, then Info. The Server section shows the PHP memory limit, and the WordPress Constants section shows WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT. With shell access, WP-CLI can print the values too.
Is 256M a Good WordPress Memory Limit?
It is a common and reasonable value for most sites, and it matches the WordPress admin default. Stores and heavy page builders may need more, but measure peak usage first rather than guessing.
Can Adding php_value to .htaccess Break My Site?
Yes. On servers running PHP-FPM or Nginx, php_value lines in .htaccess cause a 500 Internal Server Error. Remove the line and use a .user.ini file or the host’s PHP settings instead.
Should I Set the Memory Limit to -1?
No, not on a live site. -1 removes the limit completely, so a broken plugin or endless loop can use all of the server’s memory and affect every visitor. Use a measured value with headroom instead.