Encodera

Thanks for reading!

Donate to the site — we work hard for you.

Contents

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 list

It 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 --help

Developer mode

After installation the default mode is active. For working on code it is changed right away:

bin/magento deploy:mode:set developer

The 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

CommandWhat it does
module:statusShows enabled and disabled modules
module:enable NameEnables a module
setup:upgradeRegisters new modules, updates tables, runs patches
cache:cleanCleans the Magento cache
cache:flushEmpties the whole cache storage
indexer:reindexRecalculates catalog indexes
setup:di:compileGenerates 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 changedWhat to do
A PHP file, constructor untouchedNothing
A class constructorDelete the contents of the generated folder
Any XML file in etc or a layoutbin/magento cache:clean
A .phtml templatebin/magento cache:clean if the block and page caches are on
A new module, db_schema.xml, a patchbin/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_html

The 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.

Thanks for reading!

Donate to the site — we work hard for you.