Magento 2: When should I run which commands?

Read More At: Mageprince Blog

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

EDIT:

You can run cache flush by only typing c:f without using the full command php bin/magento c:f

More info At: Create Short Forms Of Magento 2 Commands


1.When I create a new Module:

2.When I add something to Setup directory

3.When I edit etc/module.xml

php bin/magento module:enable
php bin/magento setup:upgrade

4.When I edit etc/module.xml,

5.When I edit etc/di.xml,

6.When I edit etc/webapi.xml,

7.When I edit etc/adminhtml/system.xml for xml changes cache flush is more than enough:

php bin/magento cache:flush

css and js changes: -- flush cache and php bin/magento setup:static-content:deploy


If you work with developer mode you don't need to compile when you modify xml, you can make only a setup:upgrade.

And for others modifications as css, phtml, js, only flush cache, you needn't to deploy static content.