30

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 ?

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

14 Answers 14

76

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.

| improve this answer | | | | |
  • 1
    thanks @rakesh it saves my time thank you very much once again – Nagaraju K Oct 13 '17 at 12:50
  • 1
    Take care, increasing memory limit can be only a temporary solution. – Macas Jan 25 '18 at 8:31
9

use this 'dirty' way

php -dmemory_limit=-1 bin/magento setup:di:compile
| improve this answer | | | | |
8

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

| improve this answer | | | | |
  • I tried 512mb size for my php.ini file but still not work...how solve ? – Khushbu Mehta 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 ?? – Khushbu Mehta Dec 3 '15 at 11:44
6
php -dmemory_limit=6G bin/magento setup:di:compile
| improve this answer | | | | |
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.

| improve this answer | | | | |
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.

| improve this answer | | | | |
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
| improve this answer | | | | |
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.

| improve this answer | | | | |
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.

| improve this answer | | | | |
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.

| improve this answer | | | | |
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

| improve this answer | | | | |
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.

| improve this answer | | | | |
0

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.

| improve this answer | | | | |
0

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

php -dmemory_limit=8G bin/magento setup:upgrade
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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