I am trying to execute php bin/magento setup:di:compile after enabling a custom module created on my Magento2 store. However, I am using a shared hosting which allows me to set memory_limit upto 512 MB.

Due to this compile command fails. How to run Magento 2 commands successfully on shared hosting with limited memory_limit?

[ym@webcloud1 testbed]$ php bin/magento setup:di:compile
Compilation was started.
Repositories code generation... 1/7 [====>-----------------------]  14% < 1 sec 54.0 MiB
Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory errors.

Suggestions much appreciated.

1 Answer 1


Increase the memory limit to update .php.ini file

If you have access to your php.ini file or can create one in the root, you can globally increase your allocated memory.

;adjust memory limit
memory_limit = 6G
max_execution_time = 36000
max_input_time = 36000

If you not want to update .php.ini file then use below command

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

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.