35

I have error when i add module..

Please re-run Magento compile command

so i run below command but also display error that below when run command from root,

php magento setup:di:compile

Compilation was started.
%message% 0/7 [>---------------------------]   0% 1 sec 37.0 MiB%message% 0/7 [>
---------------------------]   0% 1 sec 37.0 MiBProxies code generation... 0/7 [
>---------------------------]   0% 1 sec 37.0 MiB
Proxies code generation... 1/7 [====>-----------------------]  14% 47 secs 43.5
MiB
Repositories code generation... 1/7 [====>-----------------------]  14% 47 secs
43.5 MiB
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate
 24 bytes) in D:\xampp\htdocs\linsenwelt\vendor\zendframework\zend-code\src\Scan
ner\FileScanner.php on line 36

How to fix ?

1
  • I'm getting same error in live server
    – SIBHI S
    Commented Aug 4, 2017 at 11:01

18 Answers 18

101

A quick solution for memory limit in Magento 2 command is directly adding memory limit inside command.

For Compilation command,

php -dmemory_limit=5G bin/magento setup:di:compile

For Deployment

php -dmemory_limit=5G bin/magento setup:static-content:deploy

You can change as per 5G to max if issue not resolve.

3
  • 1
    thanks @rakesh it saves my time thank you very much once again Commented Oct 13, 2017 at 12:50
  • 1
    Take care, increasing memory limit can be only a temporary solution.
    – Macas
    Commented Jan 25, 2018 at 8:31
  • Isnt like 5G an incredible amount of MEM ... and is this M2 related or more composer related ... it feels quiet silly to give 5G's RAM ... to composer ... what is it used for?
    – snh_nl
    Commented Sep 29, 2020 at 16:23
15

use this 'dirty' way

php -dmemory_limit=-1 bin/magento setup:di:compile
1
  • This worked for me
    – Dipu R
    Commented Jul 21, 2021 at 9:02
8

Looks like your cli has only 128MB of memory allocated. Increase the value to at least 256MB or 512MB if you can.

3
  • I tried 512mb size for my php.ini file but still not work...how solve ? Commented Dec 3, 2015 at 11:36
  • If you still get Allowed memory size of 134217728 bytes then you didn't increase the memory limit for cli.
    – Marius
    Commented Dec 3, 2015 at 11:42
  • In which file i set memory limit ?? Commented Dec 3, 2015 at 11:44
7
php -dmemory_limit=6G bin/magento setup:di:compile
5

If you are using PHP >= 5.3.0 and you used the Magento 2.1.x and above, then after you run composer install, two files will be created in your root directory and your pub directory named .user.ini

Edit those files to override your PHP.ini settings, in this case is the memory_limit

; Set PHP memory limit to 768M which already enough for compilation tasks
memory_limit = 768M
max_execution_time = 18000

If you are using Apache, you will need to care the files inside root directory only, not the /pub one and vice versa if you are using engineX (nginx)

Hope it helps.

3

You need to increase memory allocated to php. To increase memory, execute command php --ini . Findout loaded php.ini. It should be like

Configuration File (php.ini) Path: /etc/php5/cli
Loaded Configuration File:         /etc/php5/cli/php.ini
Scan for additional .ini files in: /etc/php5/cli/conf.d
Additional .ini files parsed:      /etc/php5/cli/conf.d/05-opcache.ini,

Go to current loaded php.ini (/etc/php5/cli/php.ini) and findout memory_limit parameter. Increase the value against memory_limit parameter to 256M or 512M.

3

This situation can be tricky to debug since if you just to

php -r "echo ini_get('memory_limit').PHP_EOL;"

it shows the memory limit for the PHP in your path, which might be fine. But the magento script (bin/magento) uses the preamble

#!/usr/bin/env php

so it is not necessarily using the PHP from your path! One way to track down the php.ini file which is being used is to write a small script like this:

#!/usr/bin/env php
<?php
phpinfo();

call it getinfo (not getinfo.php!), make it executable, then run it like this:

./getinfo  | grep php.ini

This will show you the ini file you need to change. In that file, change the configuration value memory_limit as suggested in other posts, to a higher value than 128M. Then save the file and check your work:

./getinfo  | grep memory_limit
2

I run into similar problem, memory limit was increased to 2Gb inside php ini file, phpinfo() file showed it was set to 2Gb. It seems Magento set memory limit manually somewhere. I increased memory limit inside file bin/magento. In first line I put this:

ini_set('memory_limit', '656M');

which made it working.

2

I have got solution for my question. For memory exhausted error, we have to add memory limit for compile code.

php -dmemory_limit=4G bin/magento setup:di:compile

Hope it will help someone in future.

1

67

A quick solution for memory limit in Magento 2 command is directly adding memory limit inside command.

For Compilation command,

php -dmemory_limit=5G bin/magento setup:di:compile

For Deployment

php -dmemory_limit=5G bin/magento setup:static-content:deploy

You can change as per 5G to max if issue not resolve.

1

I've had the EXACT same issue. It's a combination of RAM and PHP version. I have to call /opt/plesk/php/7.0/bin php -d memory_limit=3G bin/magento setup:di:compile (or flush, etc)

0

User the following line after php/bin magento -d memory_limit=5G s:d:c for your compilation code. This is due the allowed memory limit to the php. But after allowing the memory limit in the command this will remove the error and your compilation and other commands will run without any error. Just add this
-d memory_limit=5G in every command as you seen in the example above. Upvote if you found my answer useful.

0

Compilation using "-d memory_limit=5G" is not a wise decision. It's a temporary solution which may get affected during the process of Mode Switching i.e from Developer to Production. This time the system compiles the code without this logic "-d memory_limit=5G" which throws the error.

It's a better option to fix this error at this stage. To fix this, open php.ini and increase the memory_limit by 1024M and execute compile command php bin/magento setup:di:compile

Check this: https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors

This time it should work

0

for M2 add memory limit via ssh with below command.

for compile command : php -dmemory_limit=5G bin/magento setup:di:compile for deploy command : php -dmemory_limit=5G bin/magento setup:static-content:deploy

you can increase value 5G if issue not solved.

0

If you are facing this issue in the cli, please try This command:

php -dmemory_limit=8G bin/magento setup:upgrade
0

I use Plesk and I solved the issue run next command :

-bash-4.2$ /opt/plesk/php/7.3/bin/php -d memory_limit=3G bin/magento setup:di:compile

Note than 7.3 is my PHP release, instead you should apply your current PHP release.

1
  • Now my PLesk > cron job show same error PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes). Maybe I edited something else ? Whatever I try to apply same method but do not works for me /opt/plesk/php/7.3/bin/php -d memory_limit=3G /var/www/vhosts/mydomain.com/subdomain.mydomain.com/bin/magento cron:run 2>&1 Any help I will apreciatte Commented Oct 22, 2020 at 12:30
0

If you are using WAMP, the folder C:\wamp64\bin\php\php<your-version> contains two php ini files: php.ini and phpForApache.ini

Look for memory_limit option and set to afford your needs, I set mine to 9999M in both files.

Hope it helps

0

Open = php.ini File

nano /usr/local/etc/php/8.1

  • memory_limit 4G

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.