April 10, 2021

Did you run bin/magento random:command?

Inexperienced Magento developers often try to solve their problems by running all the magento commands repeatedly and compulisively.

To be honest, this usually works just before going crazy.

So let’s see the most common commands and what kind of problems they solve. (Then we will probably run them all again randomly out of frustration)

Flush the cache

bin/magento cache:flush

This just flush the cache. It’s needed when:

  • You don’t see changes in blocks or templates
  • You don’t see configuration changes

Setup upgrade

bin/magento setup:upgrade

This updates the Magento database scheme and data. It’s useful if:

  • You just installed a new module and everything broke apart
  • You have updated a module (or Magento itself) and you don’t see what expected
  • You don’t see the changes you expect in the database

Compile frontend code

bin/magento setup:static-content:deploy

This generates static files (html, css and js only) and puts them in the pub/static folder. It helps when:

  • You don’t see your frontend changes
  • You added a new static file to your theme
  • You overrided some magento core static file

Compile backend code

bin/magento setup:di:compile

This generates backend code and updates the dependency injection configuration. It’s used in these circumstances:

  • You just added a new php class with its dependencies
  • You just installed a new module
  • You see a php exception on your screen for a missing class and this class exists
Irene Iaccio

Freelance web developer