Magento 2 CLI Commands Every Developer Should Know
Learn the most important Magento 2 CLI commands for cache management, module administration, cron jobs, deployments, indexing, maintenance mode, and development workflows.
Why Use Magento 2 CLI?
Magento 2 Command Line Interface (CLI) is a powerful tool that helps developers manage stores, deploy code, clear caches, configure modules, run indexers, manage cron jobs, and automate administrative tasks. Understanding these commands can significantly improve development efficiency and simplify store maintenance.
Cache Management Commands
Clean Cache
php bin/magento cache:clean
Removes enabled cache types without deleting generated cache files.
Flush Cache
php bin/magento cache:flush
Completely clears all cache storage used by Magento.
View Cache Status
php bin/magento cache:status
Module Management Commands
Enable Module
php bin/magento module:enable Vendor_Module
Disable Module
php bin/magento module:disable Vendor_Module
Module Status
php bin/magento module:status
Setup Commands
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f
Used after installing extensions, updating modules, or deploying new code.
Index Management Commands
php bin/magento indexer:status
php bin/magento indexer:reindex
Rebuild Magento indexes to improve storefront performance and data accuracy.
Cron Management Commands
Magento depends on cron jobs for emails, indexing, catalog price rules, newsletters, sitemap generation, and many background processes.
Install Magento Cron
php bin/magento cron:install
Remove Magento Cron
php bin/magento cron:remove
View Current Cron Jobs
crontab -l
Edit Cron Jobs
crontab -e
Run Cron Manually
php bin/magento cron:run
Maintenance Mode Commands
php bin/magento maintenance:enable
php bin/magento maintenance:disable
php bin/magento maintenance:status
Maintenance mode prevents customers from accessing the store during deployments and upgrades.
Developer & Production Mode Commands
php bin/magento deploy:mode:set developer
php bin/magento deploy:mode:set production
php bin/magento deploy:mode:show
Switch between developer and production modes based on your environment.
Common Deployment Command Sequence
php bin/magento maintenance:enable
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush
php bin/magento maintenance:disable
This sequence is commonly used after deploying new code or installing Magento extensions.
Conclusion
Magento 2 CLI commands are an essential part of every developer's workflow. Whether you're managing cache, deploying code, configuring cron jobs, enabling modules, rebuilding indexes, or maintaining production environments, mastering these commands will help you work faster and more efficiently.