Magento – Magento 2: Controlling M2 via command line – when and why to use each command

clicommand linemagento2

When making changes to my Magento 2 site, I usually run a few of the command line commands to 'refresh' my site to see the changes I've made. The problem is, I'm not too sure what each command really does and when to use a particular one… Meaning I usually run a lot of them 'just to make sure' the site's refreshed and my changes will take effect.

When I make changes to the template layout.xml files I just use

php bin/magento cache:clean

If I make changes to the .phtml files or .php files, I usually run:

php bin/magento setup:static-content:deploy
php bin/magento setup:upgrade
php bin/magento cache:clean

and php bin/magento cache:flush – just to make sure!

I have no doubt this is overkill and I'm using some commands unnecessarily.

Could someone explain what each command actually does and when (and why) it would be correct to use each one?

Here's a list of commands which I think would be useful to know the reasons for using each of them:

  1. php bin/magento cache:clean
  2. php bin/magento cache:flush
  3. php bin/magento setup:static-content:deploy
  4. php bin/magento setup:upgrade
  5. php bin/magento setup:di:deploy

For example, if I were to update a .phtml file, which commands should I run to make sure I see my changes? A .php file? layout.xml files?

Thank you!

Best Answer

I am sharing some magento 2 useful commands here:

Magento 2 Upgrade Command:

php bin/magento setup:upgrade

Magento 2 reindex Command:

php bin/magento indexer:reindex

Magento 2 flush cache Command:

php bin/magento cache:flush

Magento 2 static content deploy Command:

php bin/magento setup:static-content:deploy

Magento 2 check developer mode Command:

php bin/magento deploy:mode:show

Magento 2 set developer mode Command:

php bin/magento deploy:mode:set developer
php bin/magento deploy:mode:set production

Magento 2 static content deploy Command if get memory error:

php -dmemory_limit=6G bin/magento setup:static-content:deploy

Magento 2 Disable module command:

php bin/magento module:disable Module_Name

Magento 2 enable module command:

php bin/magento module:enable Module_Name

Magento 2 command to find the all disabled/enabled module command:

php bin/magento module:status
Related Topic