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 ?

  • I'm getting same error in live server – SIBHI S Aug 4 '17 at 11:01

A Quick solutions for memory limit in magento 2 command is directly adding memory limit inside commannd,

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
    thanks @rakesh it saves my time thank you very much once again – Nagaraju Kasa Oct 13 '17 at 12:50
  • 1
    Take care, increasing memory limit can be only a temporary solution. – Macas Jan 25 at 8:31

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

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

use this 'dirty' way

php -dmemory_limit=-1 bin/magento setup:di:compile

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.

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

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.

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.

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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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