Magento is a powerful ecommerce CMS that provides many CLI commands to perform multiple operations in a Magento application. These commands are added to the bin/magento and can be used through the command line for local access, or you need the SSH access to your server to use these commands.
Below are some useful Magento-2 CLI commands.
Create admin user:
php bin/magento admin:user:create –admin-user=’admin’ –admin-password=’admin123′ –admin-email=’[email protected]’ –admin-firstname=’Admin’ –admin-lastname=’User’
Unlock admin user account:
php bin/magento admin:user:unlock username
Uninstalling the Magento application:
php bin/magento setup:uninstall
Cache cleaning:
php bin/magento cache:clean
Cache cleaning with specific type:
php bin/magento cache:clean cache_type
Disable cache:
php bin/magento cache:disable
Disable cache with specific type:
php bin/magento cache:disable cache_type
Enable cache:
php bin/magento cache:enable
Enable cache with specific type:
php bin/magento cache:enable cache_type
Flush cache:
php bin/magento cache:flush
Flush cache with specific type:
php bin/magento cache:flush cache_type
Check cache status:
php bin/magento cache:status
Setup upgrades:
php bin/magento setup:upgrade
Setup upgrades without removing pub/static files:
php bin/magento setup:upgrade –keep-generated
Static content deploy:
php bin/magento setup:static-content:deploy or php bin/magento -f setup:static-content:deploy
Deploy for specific language:
php bin/magento setup:static-content:deploy en_US
Deploy for Magento backend theme:
php bin/magento setup:static-content:deploy –theme=”Magento/backend”
Static content deploy for specific themes:
php bin/magento setup:static-content:deploy –theme Magento/luma –theme Magento/theme_number_two
Exclude themes on static content deploy and does not minify HTML files:
php bin/magento setup:static-content:deploy en_US –exclude-theme Magento/luma –no-html-minify
DI compilation:
php bin/magento setup:di:compile
See all modules status:
php bin/magento module:status
Enable module:
php bin/magento module:enable VendorName_ModuleName
Disable module:
php bin/magento module:disable VendorName_ModuleName
Uninstall module:
php bin/magento module:uninstall VendorName_ModuleName
Reindexing:
php bin/magento indexer:reindex
List of indexers:
php bin/magento indexer:info
View indexer status:
php bin/magento indexer:status
Show the mode of all indexers:
php bin/magento indexer:show-mode
Reset indexer status to invalid:
php bin/magento indexer:reset
Set index mode type:
- realtime: update on save
- schedule: Sets the specified indexers to save according to the cron schedule.
php bin/magento indexer:set-mode {schedule|realtime} [indexer]
Set developer mode:
php bin/magento deploy:mode:set developer
Set production mode:
php bin/magento deploy:mode:set production
Check current mode:
php bin/magento deploy:mode:show
Enable maintenance mode:
php bin/magento maintenance:status
Enable maintenance mode for all clients except specific IPs:
php bin/magento maintenance:enable –ip=xxx.x.x.1 –ip=xxx.x.x.2
Allow IP on maintenance mode:
php bin/magento maintenance:allow-ips –ip=xxx.x.x.1 –ip=xxx.x.x.2
Disable maintenance mode:
php bin/magento maintenance:disable
Check maintenance mode status:
php bin/magento maintenance:status
Creates resized product images:
php bin/magento catalog:images:resize
Removes unused product attributes:
php bin/magento catalog:product:attributes:cleanup
Set Magento crontab:
php bin/magento cron:install –force
Run jobs by schedule:
php bin/magento cron:run
Remove Magento crontab:
php bin/magento cron:remove
Uninstall language packages:
php bin/magento i18n:uninstall [-b|–backup-code] {language package name}
Print list of available backup files:
php bin/magento info:backups:list
List of available currencies:
php bin/magento info:currency:list
List of available language locales:
php bin/magento info:language:list
Display the list of available timezones:
php bin/magento info:timezone:list
Clear the list of IPs:
php bin/magento maintenance:enable –ip=none
Display the list of stores:
php bin/magento store:list
Display the list of websites:
php bin/magento store:website:list
Take a backup of Magento Application code base, media, and database:
php bin/magento setup:backup