Increase WordPress Memory Limit: WP_MEMORY_LIMIT vs PHP memory_limit for Managing Site Resources

Set PHP memory_limit high enough first, then set WP_MEMORY_LIMIT inside WordPress if the site needs a clear application-level cap. WordPress tries to use 40 MB on single-site installs and 64 MB on multisite installs, while the admin area may request a higher ceiling through WP_MAX_MEMORY_LIMIT [source: WordPress Developer Resources]. If PHP is capped at 128 MB, WordPress cannot reliably use 256 MB just because you typed it into wp-config.php. Fix the server ceiling first, then tune WordPress.

TLDR: php.ini memory_limit is the hard server-side ceiling for PHP scripts. WP_MEMORY_LIMIT is WordPress asking PHP for a limit, but it usually cannot beat the server cap. For example, a WooCommerce store hitting “Allowed memory size exhausted” at 128 MB may stop failing after raising PHP memory_limit to 256M and setting WP_MEMORY_LIMIT to 256M; one realistic result is failed checkout attempts dropping by 18% over seven days. Do not raise memory blindly; measure first, then change one layer at a time.

What PHP memory_limit controls

memory_limit is a PHP setting. It controls how much memory a single PHP process can use before PHP kills it with a fatal error. That error often looks like this:

Fatal error: Allowed memory size of 134217728 bytes exhausted…

That number is not random. 134,217,728 bytes equals 128 MB. If you see it, your request ran into the PHP ceiling.

This setting applies beyond WordPress. It affects plugins, themes, cron jobs, imports, AJAX requests, REST API calls, and admin screens. If PHP-FPM or your hosting panel says 128M, WordPress is working inside that box.

The PHP manual describes memory_limit as the maximum amount of memory a script may consume [source: PHP manual]. That makes it the real upper boundary in most hosting setups.

Image not found in postmeta

What WP_MEMORY_LIMIT controls

WP_MEMORY_LIMIT is a WordPress constant. You normally define it in wp-config.php. It tells WordPress what memory limit it should try to set for normal front-end and back-end requests.

Example:

define('WP_MEMORY_LIMIT', '256M');

Place it above this line:

/* That's all, stop editing! Happy publishing. */

The catch is that this can feel fake when the server refuses the change. WordPress may request 256M, but if PHP, the host, or a container limit blocks it, the request fails or is ignored. It drives me crazy that many dashboards still show the WordPress value as if the server agreed. Always verify the real PHP value too.

The difference in plain terms

  • PHP memory_limit: the server-level PHP cap. It is usually the strongest rule.
  • WP_MEMORY_LIMIT: the WordPress runtime request for regular site operations.
  • WP_MAX_MEMORY_LIMIT: a higher WordPress cap often used for admin tasks, updates, image processing, and imports.

Think of PHP as the building owner and WordPress as a tenant. WordPress can ask for a larger room. PHP decides whether that room exists.

Which value wins?

In most cases, the lower effective limit wins. If PHP is set to 128M and WordPress asks for 256M, the site may still hit 128M. If PHP is 512M and WordPress asks for 256M, WordPress requests 256M for its own work.

Some hosts also disable runtime memory changes. In that case, WP_MEMORY_LIMIT may do almost nothing. Shared hosting is often strict here. VPS and dedicated servers give you more control, but also more ways to misconfigure things.

How to change PHP memory_limit

Your method depends on the hosting stack. Common options include:

  • Hosting control panel: look for PHP options, PHP selector, or MultiPHP INI Editor.
  • php.ini: add or edit memory_limit = 256M.
  • .user.ini: common on PHP-FPM setups; add memory_limit = 256M.
  • .htaccess: sometimes works with Apache module PHP using php_value memory_limit 256M.
  • Container settings: Docker, Kubernetes, and managed platforms may impose memory outside PHP.

If one method causes a 500 error, remove it. Your server may not permit that configuration style.

How to change WordPress memory limits

Add these lines to wp-config.php only after confirming your PHP ceiling can support them:

define('WP_MEMORY_LIMIT', '256M');
define('WP_MAX_MEMORY_LIMIT', '512M');

Use WP_MAX_MEMORY_LIMIT carefully. It can help with media regeneration, backups, and large imports. It can also let heavy admin actions consume a lot of RAM very quickly.

Image not found in postmeta

Recommended values for real sites

There is no perfect number. Still, these ranges are sensible starting points:

  • Small blog: 128M PHP limit, 128M WordPress limit.
  • Business site with page builder: 256M PHP limit, 256M WordPress limit.
  • WooCommerce store: 256M to 512M PHP limit, 256M WordPress limit, 512M admin max if needed.
  • Large import or migration: temporary 512M or higher, then reduce after the task.

Do not set memory_limit = -1 unless you are debugging on a controlled machine. Unlimited memory sounds easy. It can crash a server under load.

Why more memory is not always the fix

Raising memory can hide bad code. A plugin that loads 80,000 rows on every page will still be wasteful at 512M. A theme that builds huge option arrays will still slow down requests. Expect to waste time on this if you treat memory as the only symptom.

Check these issues before doubling limits again:

  • Oversized autoloaded options in the database.
  • Backup plugins running during peak traffic.
  • Image optimization jobs processing too many files at once.
  • Product filters loading every variation in memory.
  • Page builders with bloated templates and unused modules.
  • Object cache misconfiguration.

How to verify the active limit

Use more than one method. WordPress admin screens can be helpful, but server rules may still differ by context.

  • Check Tools > Site Health > Info > Server.
  • Create a temporary phpinfo() file and read memory_limit.
  • Use WP-CLI: wp eval 'echo ini_get("memory_limit");'
  • Review PHP error logs after a failed request.
  • Ask your host whether PHP-FPM pool limits or container limits also apply.

Delete any phpinfo() file after checking. It exposes server details that should not stay public.

Image not found in postmeta

A safe process for increasing memory

  1. Record the current value. Note PHP memory, WordPress memory, and the exact error message.
  2. Raise PHP first. Move from 128M to 256M, not from 128M to unlimited.
  3. Set WordPress second. Match WP_MEMORY_LIMIT to the needed site value.
  4. Test the failing action. Repeat the checkout, import, update, or media task.
  5. Watch logs for 24 to 72 hours. One clean test is not proof.
  6. Profile if errors continue. Find the plugin, query, or process that consumes memory.

Final recommendation

Use PHP memory_limit as the true resource boundary and WP_MEMORY_LIMIT as the WordPress-specific request inside that boundary. For many modern WordPress sites, 256M is a practical baseline. Stores, builders, multilingual plugins, and import-heavy sites may need more.

The serious approach is simple: raise memory only to the level the workload justifies, verify the active limit, and keep checking logs. More memory can make a site stable. It should not become a cover for broken plugins, oversized queries, or careless hosting limits.