Set PHP memory_limit first, then set WordPress WP_MEMORY_LIMIT below it. That is the safest fix for most WordPress memory errors. WordPress can ask PHP for more memory, but PHP still controls the ceiling. WordPress commonly uses 40 MB as a default memory limit for single-site installs and 64 MB for multisite, while some admin tasks may request more [source: WordPress.org].
TLDR: If you see “Allowed memory size exhausted,” raise the server’s PHP memory_limit first, then set WP_MEMORY_LIMIT in wp-config.php. For example, a WooCommerce shop with 35 plugins may fail at checkout on 128M, but run normally after PHP is raised to 512M and WordPress is set to 256M. Do not just paste random code into WordPress and hope. Check the real PHP limit, because that is the hard stop.
What the error really means
A WordPress memory error usually looks like this:
Fatal error: Allowed memory size of 134217728 bytes exhausted.
That number is not random. 134217728 bytes equals 128 MB. PHP hit its configured memory cap while running a script. The script may be loading a page, processing an image, running a backup, importing products, building a cache, or serving a heavy admin screen.
Expect to waste time on this if you only change one setting and never verify it. Many sites have three or four places where memory can be defined. The hosting panel may say one thing. PHP may report another. WordPress may try to set a third value. Only the value PHP actually uses matters when the request runs.
PHP memory_limit: the hard server limit
memory_limit is a PHP configuration setting. It controls how much memory one PHP process can use. Since WordPress runs on PHP, this setting sits above WordPress.
You can usually change it in one of these places:
- Hosting control panel, such as cPanel, Plesk, or a custom dashboard.
php.ini, often used on VPS or dedicated servers..user.ini, common on PHP FPM hosting..htaccess, on some Apache setups.- Container or server config, for Docker, Nginx, or managed stacks.
If PHP is set to 128M, WordPress cannot reliably use 256M, even if you define it in wp-config.php. WordPress may request it, but PHP may refuse. That is why raising only WP_MEMORY_LIMIT often changes nothing.
WP_MEMORY_LIMIT: the WordPress request
WP_MEMORY_LIMIT is a WordPress constant. You define it in wp-config.php. It tells WordPress how much memory it should try to use for normal site requests.
A common setting looks like this:
define( 'WP_MEMORY_LIMIT', '256M' );
Place it above this line:
/* That's all, stop editing! Happy publishing. */
This setting is useful, but it is not magic. It depends on PHP allowing the value. If your host caps PHP at 128M, then setting WordPress to 512M is mostly wishful thinking.
It drives me crazy that many tutorials skip this part. They show one line of code, then act like the server does not exist. On a shared host, the server limit may be locked. On managed WordPress hosting, you may need support to raise it.
WP_MAX_MEMORY_LIMIT: admin and heavy tasks
There is also WP_MAX_MEMORY_LIMIT. This is used for heavier WordPress tasks, especially in the admin area. Think updates, imports, media processing, backups, and some editor actions.
You may define both values like this:
define( 'WP_MEMORY_LIMIT', '256M' );
define( 'WP_MAX_MEMORY_LIMIT', '512M' );
A practical setup for a busy store might be:
- PHP
memory_limit: 512M WP_MEMORY_LIMIT: 256MWP_MAX_MEMORY_LIMIT: 512M
This gives normal page loads a reasonable cap. It also gives admin jobs more room. That matters on WooCommerce, LMS, membership, multilingual, and page-builder sites.
Which value should be higher?
PHP memory_limit should be equal to or higher than any WordPress memory value. That is the clean rule.
Use this order:
- Set PHP
memory_limitto the highest value you want to allow. - Set
WP_MEMORY_LIMITfor public and normal WordPress requests. - Set
WP_MAX_MEMORY_LIMITfor admin and heavy jobs. - Test the error again.
- Check actual memory usage, not just configured numbers.
For a simple blog, 128M may be fine. For a business site with a page builder and 20 plugins, 256M is more realistic. For WooCommerce, large imports, or heavy admin tasks, 512M is often sensible. Some large sites need more, but raising memory forever is not a fix. It can hide bad code.
How to check the real memory limit
The easiest method is WordPress Site Health. Go to Tools > Site Health > Info > Server. Look for the PHP memory limit. This shows what WordPress sees from PHP.
You can also create a temporary PHP info file, if your host allows it:
<?php phpinfo();
Upload it, visit it in a browser, and search for memory_limit. Delete the file after checking. Do not leave it public. It can expose server details.
WP-CLI users can run:
wp eval 'echo ini_get("memory_limit");'
That gives a cleaner answer. It shows the limit PHP reports to WordPress in that environment.
How to raise PHP memory_limit
If you use cPanel or a similar panel, look for Select PHP Version, PHP Options, or MultiPHP INI Editor. Set memory_limit there. Save, then restart PHP if the panel offers that option.
On a server with php.ini, use:
memory_limit = 512M
On some hosts, .user.ini works:
memory_limit = 512M
On older Apache setups, this may work in .htaccess:
php_value memory_limit 512M
If that causes a 500 error, remove it. Your server does not allow that directive there.
When raising memory is the wrong fix
Memory errors can point to deeper problems. If a site suddenly needs twice the memory after a plugin update, check that plugin. If one admin page takes 18 seconds longer than usual and then crashes, inspect what loads on that page.
Common causes include:
- Heavy page builders loading large editor assets.
- Bad plugin updates or memory leaks.
- Huge image processing, especially uncompressed uploads.
- Large WooCommerce reports or product imports.
- Backup plugins trying to package everything in one request.
- Object cache issues storing too much data per request.
A safe troubleshooting order
Start with a backup. Then work through the issue in a controlled way.
- Confirm the exact error in the PHP error log.
- Check the current PHP memory limit in Site Health or WP-CLI.
- Raise PHP
memory_limitto a reasonable value. - Add WordPress constants in
wp-config.php. - Retest the failed action, such as checkout, import, or update.
- Disable suspect plugins only if the error continues.
- Ask the host for logs if the limit appears stuck.
A clean baseline for many serious WordPress sites is:
define( 'WP_MEMORY_LIMIT', '256M' );
define( 'WP_MAX_MEMORY_LIMIT', '512M' );
Pair that with PHP:
memory_limit = 512M
This setup will not fix broken code. But it removes the most common ceiling. It also gives WordPress enough room for normal growth without opening the door to unlimited memory use.
Final recommendation
Treat memory_limit as the server rule and WP_MEMORY_LIMIT as the WordPress request. Raise the server cap first. Then set WordPress limits that fit the site’s workload.
If the error returns at 512M, stop guessing. Review plugins, logs, cron jobs, imports, and recent changes. More memory can buy time. It should not become a permanent cover for inefficient code.