I get "Fatal error: Allowed memory size of 41943040 bytes exhausted" when importing demo content. I tried define('WP_MEMORY_LIMIT') but nothing changed.
DEV3 Developer Forum
How do I increase the WordPress memory limit when I see "Allowed memory size exhausted"?
Ask a question
Every post is reviewed first. Usually reviewed within 24 hours.
dev3 ·
0
1 reply
dev3 · Accepted answer
There are two limits. WP_MEMORY_LIMIT asks WordPress to raise PHP's memory_limit, but it can only raise it up to what the server allows. Your 41943040 bytes is 40 MB, which looks like a host cap.
Set WordPress side in wp-config.php:
define( 'WP_MEMORY_LIMIT', '256M' ); // front end
define( 'WP_MAX_MEMORY_LIMIT', '512M' ); // admin, imports, image resizing
Set the PHP side (the real fix when the above is ignored). Use one that your host supports:
; php.ini or .user.ini in the site root
memory_limit = 256M
# .htaccess (Apache with mod_php only)
php_value memory_limit 256M
On PHP-FPM, edit the pool or php.ini and restart: sudo systemctl restart php8.3-fpm. On shared hosting use the control panel's PHP settings screen.
Verify: Tools > Site Health > Info > Server shows "PHP memory limit". Or wp eval 'echo ini_get("memory_limit");'.
Pitfalls
- If the value stays at 40M or 64M, the host enforces it; you need to ask support or move to a plan that allows more.
- Raising memory hides leaks. If a single page needs more than 256M, find the cause: a heavy plugin, an unpaginated query, or huge images. Query Monitor helps.
- Cloud setups with a container memory cap kill the process regardless of
memory_limit.
0