Problem:


I have an error when I add a module..

Please re-run the Magento compile command

so i run the below command, but also display error below when run the 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.5MiB 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

 

Solution 1:

A quick solution for the memory limit in Magento 2 command is to directly add the memory limit inside the command.

For the 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 the issue is not resolved.

 

Solution 2:

 

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 the root directory only, not the /pub one and vice versa if you are using engineX (nginx)

 

Hope it helps.