3

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!

1

3 Answers 3

7

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
4
  • php magento/bin cache:clean : It cleans a cache type = deletes all items from enabled Magento cache types only. This option does not affect other processed or applications because it cleans only the cache that Magento uses. Disabled cache types are not cleaned. Equivalent of clicking the Flush Magento Cache button in the backend.

To use when a modification in a file does not show up.

  • php magento/bin cache:flush : it flushes a cache type = purges the cache storage, which might affect other processes applications that are using the same storage. Equivalent of clicking the Flush Cache Storage button in the backend.

To use when a modification in a file does not show up and the cache cleaning did not help.

Extra information regarding caching: http://devdocs.magento.com/guides/v2.0/config-guide/cli/config-cli-subcommands-cache.html

  • php magento/bin setup:static-content:deploy : it writes the static files to the Magento file system when Magento is set for production mode. Static files are located under the pub/static directory and some are cached in the var/view_preprocessed directory.

To use to deploy static view files when using the production mode

Extra information regarding static file deployment: http://devdocs.magento.com/guides/v2.0/config-guide/cli/config-cli-subcommands-static-view.html

  • php magento/bin setup:upgrade : it updates the Magento software. Useful when you add a new module to update the database schema.

To use after installing/updating a module or after installing/upgrading Magento

Extra information regarding magento setup script: http://devdocs.magento.com/guides/v2.0/install-gde/install/cli/install-cli-subcommands.html

  • php magento/bin setup:di:deploy : it runs the compiler to generate code and dependency injection

To use to compile the code

Extra information regarding the compiler: http://devdocs.magento.com/guides/v2.0/config-guide/cli/config-cli-subcommands-compiler.html

2
  • Thank you for the explanation. Could you expand on a few of them so I know when the best time would be to use each one? Your comment on php magento/bin setup:upgrade is very helpful, as it explains when I should use that command.
    – MikeMason
    Commented Apr 26, 2016 at 9:17
  • @MikeMason see my edit Commented Apr 26, 2016 at 9:46
2

php magento/bin cache:clean Cleaning a cache type deletes all items from enabled Magento cache types only. In other words, this option does not affect other processes or applications because it cleans only the cache that Magento uses. Disabled cache types are not cleaned.

if your cache are enable in admin that time, if you edit xml file you must required this command to see chagnes.

For .phtml file case, Your cache are enable in admin this command is used for see changes. If you have disable only full_page_cache from admin and all others are enable that time you doesn't required to call this command.

php magento/bin cache:flush Flushing a cache type purges the cache storage, which might affect other processes applications that are using the same storage.

php magento/bin setup:static-content:deploy

This is used for deployment of your theme. Using this command if you have create new theme and want to deploy new theme then its useful. Ex. If you want to override base module web/template/*.html file into your theme, Its must run this command to affect the chagnes on frontend.

If you are changing Frontend Development workflow from admin,

Stores -> Configuration -> Advanced -> Frontend Development workflow

Changes type from server side to client side less compilation in develoer mode. This command is useful for above schenario.

php magento/bin setup:upgrade, This command is used for updates the Magento sites. its required when you add a new module to update the database schema or upgrade already installed module to see changes.

php magento/bin setup:di:deploy: This command is used for compiler generation code and dependancy injections.

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.