Magento 2 – When to Run Which Commands

command linemagento2

I have been working with Magento 2 for 2 months now. I realized that I am using bin/magento setup:upgrade way too much. I think I do not know when I have to run that command.

Here are the situations that I run the aforementioned command.

  • When I create a new Module,
  • When I add something to Setup directory,
  • When I edit etc/module.xml,
  • When I edit etc/di.xml,
  • When I edit etc/webapi.xml,
  • When I edit etc/adminhtml/system.xml

Question: In which situations is it absolutely necessary to run bin/magento setup:upgrade command?

(The reason I am asking is that it takes some time finish that command. I believe that it can really improve the productivity if I stop using it unnecessarily.)

Best Answer

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

Related Topic