We as System Admin often see many Magento developers running the Magento commands every time they change something like css, js or HTML.
Here, I will discuss which Magento changes require which commands to reflect changes on the frontend or backend of Magento 2.
A. php bin/magento cache:flush (or php bin/magento c:f)
php bin/magento cache:flush
or
php bin/magento c:f
You need to run this command, If you made changes in admin configuration, layout xml, ui component, phtml, … file or overwrite html, css, js in frontend theme.
Here is the list of caches in Magento 2
- Configuration: After adapting configuration files, it is necessary to flush them including configuration and store specific settings
- Layouts: After adapting layout files, it is necessary to flush them including the compiled page layout from all components
- Blocks HTML output: After adapting the view layers, it is necessary to flush them including page fragments per block
- Collections Data: By Magento, it can flush automatically database queries. However, Custom modules may write entries which make Magento can not clean by itself, in case, Magento can not clean so we need to clean the cache
- Reflection Data: API interfaces reflection data will be flushed
Database DDL operations: it can be flush automatically by Magento, but 3rd party can plus more data, after making custom changes to the database schema, which can clean the cache - EAV types and attributes: The metadata regarding the entity attributes into the cache, in general, it should not flush the cache
- Integrations Configuration: Caches the compiled integrations on your store. Clean after adding new or changing existing integrations
- Integrations API Configuration: Compiled integration APIs configuration of the Store’s Integrations
- Page Cache: This cache links the HTML pages so it is necessary to clean this type of cache regularly
- Translations: After merging translations from all modules, the merger cache will be cleaned
- Web Services Configuration: Caching the Web API Structure
B. php bin/magento setup:upgrade (or php bin/magento s:up)
php bin/magento setup:upgrade
or
php bin/magento s:up
You should run this command only on following senarios
- When you made changes in the Setup script(InstallData, InstallSchema,
UpgradeData, UpgradeSchem) - When you install a new module
- When you change
setup_version
in module.xml - After upgrade Magento version
C. php bin/magento setup:di:compile (or php bin/magento s:d:c)
php bin/magento setup:di:compile
or
php bin/magento s:d:c
If you made changes like add new dependency in __construct(), changes in di.xml
, Add new controller…
If you are in developer mode you can simply delete changed files from var/generation
folder for Magento 2.2.x version and /generated
folder for Magento 2.3.x and above.
D. php bin/magento setup:static-content:deploy (or php bin/magento s:s:d)
php bin/magento setup:static-content:deploy
or
php bin/magento s:s:d
You need to run this command only when you made changes in HTML, CSS, JS…
If you are in developer mode and enabled symlinks in system you need not run this command. If disabled symlinks, need to delete particular changed files from pub/static
folder or run the command.
D. php bin/magento indexer:reindex (or php bin/magento i:rein)
php bin/magento indexer:reindex
or
php bin/magento i:rein
Sometimes not all indexers are reindexed using admin reindex even if time & date is showing as updated in magento admin. In that scenario, to double check the reindex process we should use the SSH/CLI reindex method below.
Reindex all Magento 2 indexers:
php bin/magento indexer:reindex
Check the status of the indexers:
php bin/magento indexer:status
Show the list of the indexers:
php bin/magento indexer:info
Reset the index which is in “Reindex required” state:
php bin/magento indexer:reset [index_name]
Reindex each indexer that has status “Reindex required”:
php bin/magento indexer:reindex [index_name]