What the message looks like
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /var/www/html/wp-includes/class-wp-image-editor-imagick.php on line 612Common causes
memory_limitis too low for the task: resizing large images, a big import, Composer, a heavy plugin.- A loop or a query loads far too much data into memory at once.
- A memory leak in a long-running script or worker.
- The limit was raised in the wrong
php.ini: the CLI and PHP-FPM read different files. - A hosting panel or pool setting overrides the global value.
Check
- Which php.ini does the command line use, and what is the limit?
php --ini; php -r 'echo ini_get("memory_limit"), PHP_EOL;' - Where is memory_limit set for FPM?
grep -rn 'memory_limit' /etc/php/*/fpm/ - Which line failed? Read the log
grep -i 'memory size' /var/log/nginx/error.log /var/log/php8.3-fpm.log | tail -n 10
Fix
- Raise the limit in the file PHP-FPM uses, for example
memory_limit = 512Min/etc/php/8.3/fpm/php.ini, thensystemctl reload php8.3-fpm. - Per pool, set
php_admin_value[memory_limit] = 512Min the pool file. - On a panel such as Plesk, change the value in the domain's PHP settings.
- For Composer, run
COMPOSER_MEMORY_LIMIT=-1 composer installonce. - If the script keeps growing, fix the cause: process data in chunks, free large variables, avoid loading whole tables.
Typical scenario
A customer uploads a 24-megapixel phone photo to WordPress. The media library aborts, and the PHP log reads "Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes)". The upload itself is small enough, but generating thumbnails unpacks the image into memory, which takes many times its file size. First check with phpinfo() in the browser which php.ini the web server really loads.
FAQ
Is memory_limit = -1 (unlimited) a good idea?
Not for web requests. One broken request can then use all RAM and bring the server down. Use a fixed value, large enough for your biggest legitimate task.
I changed php.ini but nothing happened.
Most likely you edited the CLI file, or PHP-FPM was not reloaded. Check which file is loaded and reload the service.
Why does the message show only a tiny number after "tried to allocate"?
That number is the last request that crossed the limit, not the total usage. The script had already consumed nearly everything before. What matters is the file path and line number in the message, which show where memory ran out.
How much memory does image processing need?
With GD roughly four bytes per pixel, because the image sits uncompressed in memory. A 24-megapixel photo lands in the range of 100 MB, regardless of the JPEG's file size. That is why large photos fail at 128 MB while small ones pass.
Does memory_limit apply per request or to the whole server?
Per script execution, so per request. The total demand is the limit times the number of concurrent workers. If you raise the limit and leave pm.max_children large, you can exhaust the server's RAM and trigger the OOM killer.