WordPress

WordPress Memory Limit: wp-config vs php.ini vs Your Host's Hard Cap

By , Lead SEO & Co-founder 8 min read
A close view of a server motherboard at night with memory sticks being seated, three labelled-by-color layers of limit switches beside it, one capped by a crimson hard stop, monitors behind showing abstract memory bars

Your WordPress memory limit isn't one setting. It's three, stacked like nesting boxes: what WordPress asks for in wp-config.php, what PHP allows in php.ini, and what your hosting plan physically lets the account use. The lowest one wins, every time.

That's why "add this line to wp-config" works for some people and does nothing for others. If the box above it is smaller, WordPress can ask all it likes. This post shows you how to read the error, find all three limits, and raise the one that's actually in the way.

If you'd rather skip the server files, send me the error through the maintenance questionnaire and I'll reply with a plan and a fixed quote within one business day.

Reading the "allowed memory size exhausted" error

The error usually looks like this, in a log or on a white screen:

Text
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted
(tried to allocate 20480 bytes) in /wp-content/plugins/some-plugin/import.php on line 88

Two numbers matter. The first is the limit that was hit, in bytes. Divide it by 1,048,576 to get megabytes: 134,217,728 bytes is 128 MB. The second number is how much more PHP wanted when it ran out, and it's usually tiny. The script didn't ask for a giant chunk. It was already full.

The file path tells you who was holding the memory at that moment. That's a clue, not a verdict. The plugin at the end of the line is sometimes just the one that walked into a room someone else filled.

On newer WordPress versions, this crash often shows up as the generic message covered in my guide to the WordPress critical error screen. Same cause, friendlier wording.

The three layers of the WordPress memory limit

Here's how the boxes nest, from the inside out.

Layer Where it's set Who controls it What happens when you hit it
WordPress WP_MEMORY_LIMIT in wp-config.php You WordPress asks PHP for more, if PHP allows it
PHP memory_limit in php.ini, .user.ini or the host panel You or the host "Allowed memory size exhausted"
Hosting account The plan's RAM or a CloudLinux limit The host only Processes killed, 500 or 503 errors

Layer 1: WP_MEMORY_LIMIT in wp-config.php

This is a request, not a command. WordPress's wp-config documentation says WordPress tries to raise PHP's memory to 40 MB (64 MB on multisite), and only if PHP currently has less than the value you enter. If PHP already allows 256 MB, setting WP_MEMORY_LIMIT to 128M changes nothing.

There's also WP_MAX_MEMORY_LIMIT, a separate, higher limit used only in the admin area for heavy jobs like resizing images and running imports. The docs note it has to be placed before wp-settings.php is loaded, which in practice means above the "That's all, stop editing" line.

Layer 2: PHP's memory_limit

This is the real ceiling for a single page load. The PHP manual lists its default as 128M and marks it changeable everywhere, which is why WordPress can raise it on the fly.

Unless the host says no. PHP lets a server admin set the limit with php_admin_value, and the PHP docs say a value set that way can't be overridden by .htaccess or ini_set(). When your host locks it like this, WordPress's request quietly fails, and your wp-config line does nothing.

Layer 3: the host's hard cap

On most shared hosting, the whole account also lives inside a box. Many cPanel hosts run CloudLinux, which gives each account a physical memory limit. When the account hits it, CloudLinux first frees cache and then kills processes, and the web server typically answers with 500 or 503 errors.

That's the tell. A PHP memory error names a byte count. A host cap usually just shows a 500 or 503 with no PHP message at all, often only during busy moments like a sale, a backup run or a crawler visit. No setting in wp-config or php.ini can raise this one. Only a bigger plan or a different host can.

How to check all three limits

Start with WordPress itself. Go to Tools > Site Health > Info. The Site Health screen has a Server section with PHP settings, including the PHP memory limit, and a WordPress Constants section that shows WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT.

If those numbers disagree with what you set, something above you is winning.

A command-line check is handy too, with one trap:

Terminal
# Prints the PHP and WordPress memory limits as WP-CLI sees them. Read-only.
# Trap: WP-CLI runs on the command-line PHP, which often has its own php.ini.
wp eval 'echo ini_get("memory_limit") . " / " . WP_MEMORY_LIMIT . " / " . WP_MAX_MEMORY_LIMIT . PHP_EOL;'

Command-line PHP often has a different, higher limit than the PHP serving your web pages. So trust Site Health for the web number, and use WP-CLI for everything else.

For the host cap, look in cPanel for Resource Usage (on CloudLinux servers) and check for memory faults. No such page? Ask support one direct question: "What's the physical memory limit for my account, and have I been hitting it?"

How to increase the WordPress memory limit (the right layer)

Work from the inside out, and stop as soon as Site Health shows the new number.

1. Raise the WordPress request. Add this to wp-config.php above "That's all, stop editing":

PHP
// Asks PHP for 256 MB on normal pages and 512 MB for admin-only heavy jobs.
// Could break: nothing directly, but it hides a memory-hungry plugin rather than fixing it.
define( 'WP_MEMORY_LIMIT', '256M' );
define( 'WP_MAX_MEMORY_LIMIT', '512M' );

2. Raise PHP's limit if step 1 didn't take. On cPanel, use MultiPHP INI Editor. On Plesk, it's PHP Settings for the domain. If your host runs PHP-FPM or FastCGI (most do in 2026), a .user.ini file in the site's root folder also works:

Config
; Sets PHP's limit for this site. Read every few minutes, not instantly.
; Could break: nothing, but the host's account cap still applies on top.
memory_limit = 256M

The PHP manual says .user.ini is only read by CGI/FastCGI setups and re-read every 300 seconds by default. So wait five minutes before deciding it didn't work.

3. Skip the old .htaccess trick. Plenty of guides still say to add php_value memory_limit 256M to .htaccess. That only works when PHP runs as an Apache module, which is rare on modern hosting. Under PHP-FPM, Apache doesn't recognize the line and usually answers with a 500 error. If that's what just happened to you, my guide to the htaccess 500 internal server error gets you back.

4. Talk to the host about the cap. If Site Health shows your new number and the site still crashes with 500s under load, you've hit layer 3. That's a plan upgrade or a move to a host with more headroom, not a config change.

Raising the upload size and max_execution_time

Big imports often hit two neighbours of the memory limit. The PHP manual's core settings list sets upload_max_filesize to 2M and post_max_size (the size of a whole form submission) to 8M by default, and says post_max_size must be larger than the upload limit. max_execution_time (how long a script may run) defaults to 30 seconds. wp-config.php can't change any of them.

Where to set them Works when
Host panel (MultiPHP INI Editor, Plesk PHP Settings) Almost always. Start here
php.ini or .user.ini in the site root .user.ini only under CGI/FastCGI or PHP-FPM
php_value lines in .htaccess Only when PHP runs as an Apache module (mod_php)

One warning: on PHP-FPM, a php_value line in .htaccess causes a 500 error, and removing it brings the site back.

Step 1: Check the current values

Go to Tools > Site Health > Info > Server and note Upload max filesize, PHP post max size and PHP time limit.

Step 2: Set the new values

Enter them in the host panel, or save this as .user.ini in the site root:

Config
; Allows uploads up to 64 MB and scripts up to 300 seconds.
; Could break: nothing, but keep memory_limit above post_max_size.
upload_max_filesize = 64M
post_max_size = 80M
max_execution_time = 300

Step 3: Confirm the change took

Wait five minutes, then reload Site Health. Media > Add New should also show the new maximum upload size. If the numbers didn't move, the host has locked them, so ask support.

How much memory does WordPress need?

A typical small business site with a page builder, a forms plugin and an SEO plugin runs comfortably with 256M. WooCommerce stores and sites with heavy imports may want the admin limit at 512M.

I don't set -1 (unlimited). The PHP manual allows it, but it means one runaway script can eat the whole account and take every other site in it down too.

Vlad's take: a higher limit is a painkiller, not a cure

Raising the limit buys time. If a site needed 128 MB last year and 512 MB today, something grew, and it will keep growing.

The usual suspects are a plugin loading too much data on every page, a bloated database, or an import that tries to swallow a whole spreadsheet at once. One quick check is autoloaded options (settings WordPress loads on every single page view):

Terminal
# Total size of settings WordPress loads on every page. Read-only.
wp option list --autoload=on --format=total_bytes

The WP-CLI docs show a healthy example at around 33 KB. If yours reads in the megabytes, an old plugin probably left a pile of data behind. From there, Query Monitor shows which plugins run the heaviest database queries on each page.

Memory and speed are the same story, by the way. Pages that need lots of memory are usually slow too, which is where my speed optimization projects tend to start.

Final Notes

Think of the WordPress memory limit as three boxes. Check all three in Site Health and your host panel, raise the innermost one that's too small, and stop there. If the numbers look right and the site still falls over under load, the host's cap is the ceiling, and no wp-config line will move it.

WordPress memory limit FAQs

What is the default WordPress memory limit?

WordPress tries to raise PHP's memory to 40 MB on a single site and 64 MB on multisite, but only if PHP currently allows less. Since PHP's own default is 128 MB, most sites actually run at 128 MB or whatever the host set. Check Tools > Site Health > Info > Server to see the real number your site is using right now.

Why isn't WP_MEMORY_LIMIT working?

Because PHP's limit or the host's account cap is lower, and the lowest limit wins. WordPress can only ask PHP for more memory. If the host locked memory_limit with php_admin_value, the request fails silently. Raise memory_limit in your host's PHP settings or a .user.ini file, wait five minutes, and check Site Health again. If it still won't move, ask the host.

How do I fix "allowed memory size exhausted" in WordPress?

Find the limit in the message (divide the bytes by 1,048,576 to get megabytes), then raise WP_MEMORY_LIMIT in wp-config.php and PHP's memory_limit in the host panel to 256M. If the error returns at the new limit, a plugin or import is leaking memory. Deactivate the plugin named in the error and test again before raising the limit further.

Should I set the PHP memory limit to unlimited?

No. Setting memory_limit to -1 removes the safety net. One stuck import or a buggy plugin can then use all the memory your hosting account has, which slows or crashes every site in that account. A fixed limit like 256M or 512M is safer, and it makes a memory problem show up as a clear error you can trace.

Can I increase the memory limit in .htaccess?

Only if PHP runs as an Apache module, which is rare on hosting in 2026. Most hosts use PHP-FPM, and there a php_value line in .htaccess typically causes a 500 Internal Server Error. Use your host's PHP settings page or a .user.ini file instead. If you already added the line and the site went down, delete it and the site should come back.

Next step

If memory errors keep coming back, the real fix is finding what's eating it. That's routine work in a monthly maintenance plan. Tell me about your site in the maintenance questionnaire and I'll take a look.

Want a second pair of eyes on your site?

Tell me what's going on in the wordpress maintenance questionnaire. I reply with a plan and a fixed quote within one business day.

Starting at $250/mo Start the questionnaire