The error “Allowed memory size of 134217728 bytes exhausted” means a PHP process hit its memory limit and was stopped. In Magento it typically appears during imports, reindexing, compilation, large admin grids or heavy product pages.

What Magento needs

Magento’s own requirements recommend at least 2 GB for web requests. Command-line tasks such as compilation and reindexing often need more.

Check the current limit

The web server and the command line usually use different php.ini files:

php -i | grep memory_limit
php --ini

For the web limit, look at the PHP-FPM config, for example /etc/php/8.2/fpm/php.ini.

Set it

In the PHP-FPM php.ini:

memory_limit = 2G

Then reload PHP-FPM: sudo systemctl reload php8.2-fpm. With Apache and mod_php, Magento’s .htaccess can also set it.

For one-off heavy commands, raise it only for that command:

php -d memory_limit=4G bin/magento setup:di:compile
php -d memory_limit=4G bin/magento indexer:reindex

If it still runs out

A higher limit fixes genuine size problems, not leaks. If one page or job exhausts any limit you give it, a module is loading far too much data at once, for example a whole collection without paging. The error message names the file and line where memory ran out. Start there.

Catch it automatically

MageMonitor checks for this every few minutes as part of its server checks, and alerts you by email, Slack or webhook the moment it appears, with the exact commands to fix it. See MageMonitor for Magento 2.

Related fixes