The bin/magento tool and developer mode
Almost all Magento management happens in the console: enabling a module, cleaning the cache, updating the database. The project has the bin/magento file for that. After every change, the lessons of this course name the command to run to see the result.
Running
The command is run from the project root:
bin/magento listIt prints the list of all available commands grouped by topic: cache, module, setup and others. If the file does not run directly, type php bin/magento list.
Help for a single command is shown by the --help option:
bin/magento cache:clean --helpDeveloper mode
After installation the default mode is active. For working on code it is changed right away:
bin/magento deploy:mode:set developerThe command prints Enabled developer mode. In this mode PHP errors are shown on the page instead of being hidden in a log, and styles and generated classes are created on demand.
Everyday commands
| Command | What it does |
|---|---|
module:status | Shows enabled and disabled modules |
module:enable Name | Enables a module |
setup:upgrade | Registers new modules, updates tables, runs patches |
cache:clean | Cleans the Magento cache |
cache:flush | Empties the whole cache storage |
indexer:reindex | Recalculates catalog indexes |
setup:di:compile | Generates classes in advance; needed on a production server |
What to run after a change
Magento remembers a lot: merged XML files, rendered pages, generated classes. So an edit is not always visible right away.
| What you changed | What to do |
|---|---|
| A PHP file, constructor untouched | Nothing |
| A class constructor | Delete the contents of the generated folder |
Any XML file in etc or a layout | bin/magento cache:clean |
A .phtml template | bin/magento cache:clean if the block and page caches are on |
A new module, db_schema.xml, a patch | bin/magento setup:upgrade |
Cache during development
To avoid cleaning the cache after every template edit, the caches of rendered pages and blocks are disabled:
bin/magento cache:disable full_page block_htmlThe other cache types stay enabled — without them the shop is very slow. The "Cache and indexers" lesson covers caching in detail.
Common mistake
Commands are run as a different user, for example root. Files in the var and generated folders then belong to that user, the web server cannot change them, and the page fails with a permission error. Run bin/magento as the same user that PHP runs under on the server.