This question already has an answer here:

I am having problems installing my module in magento2 I copy my module to app/code and execute :

php bin/magento setup:upgrade

And then when I try to access my magento i get an empty page and nothing works after that:

But if I execute this commands as root everything works fine:

rm -rf pub/static/* var/* generated/*;
chmod 0777 var/ pub/ generated/;
chmod 0777 -R var/ generated/ pub/;
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f
php bin/magento indexer:reindex
php bin/magento cache:clean
php bin/magento cache:flush

I don't really understand all this commands and what they exactly do, I don't want to execute something I don't understand because it's too risky.

Can someone explain to me this commands, are they safe to execute and is there a safer and simple way to install a module.


marked as duplicate by Aasim Goriya, HelgeB, Community Apr 3 at 12:39

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


You only need to run setup:upgrade command

1. When you made changes in Setup script(InstallData, InstallSchema,
UpgradeData, UpgradeSchema, ...)

2. If you install Magento first time.

3. At the time of new module installation

4. After upgrade magento version.

What will do setup:upgrade command

1) Check module version in setup_module table

2) If version not available or new version added in module.xml, It will run setup script and add latest version number in table

If you made changes in HTML, CSS, JS, ... files you need to delete particular changed files from pub/static folder or run this command

php bin/magento setup:static-content:deploy

Short Form: php bin/magento s:s:d

If you made changes like add new dependency in __construct() or changes in di.xml, you need to delete changed files from var/generation folder or run this command

php bin/magento setup:di:compile

Short Form: php bin/magento s:d:c

If you made changes in admin configuration, layout xml, ui component, phtml, ... files you need to only clean or flush cache

php bin/magento cache:flush

Short Form: php bin/magento c:f


You only need following commands to install and run a module

php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
  • Actually this two commands are not sufficient either they give me the exception : The requested class did not generate properly, because the 'generated' directory permission is read-only Thanks for the reply though. – Nicole Apr 3 at 12:27
  • try these commands, they solved the 'generated' directory permission issue for me sudo adduser abc www-data sudo adduser www-data abc Note "abc" is your system name – ASQ Apr 3 at 13:14

https://www.emiprotechnologies.com/technical_notes/magento-technical-notes-60/post/magento-2-useful-commands-list-391 search this everything is explained quite perfectly

  • Thanks but this link didn't really help for example explaining php bin/magento setup:static-content:deploy by Static Content Deploy Using Command Line is not an explanation it's just telling you if you want to deploy static content do this ... I wanted to know what are the effects of this command on my magento and on others modules will it delete or modify something which might damage your magento if not done correctly same thing for other commands ... – Nicole Apr 3 at 12:32

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