Magento 2 Useful Commands Using CLI
In Magento 1 we had very less exposure to the command line but since the start of Magento 2 command line commands have become routine hence In this article, we’ll show what is the most useful command of Magento 2 using command line interface i.e SSH. Please note that it is important that you run this command under the observation of Magento 2 expert– else there are good chances that you may break the overall setup.
Also, it is advisable that you keep the code and database backup handy in case if you wish to revert something.
You may bookmark this post for any future requirements as it is the compilation of all useful Magento 2 SSH commands. To use these commands you will need to have SSH access to your server.
MAGENTO 2 USEFUL COMMANDS LIST
1 – Upgrade Commands
Setup Upgrade Command :
php bin/magento setup:upgrade
Setup upgrades without removing pub/static files using the Command Line :
php bin/magento setup:upgrade –keep-generated
2 – Admin User Commands
php bin/magento admin:user:unlock username
Create an admin user using the Command Line:
php bin/magento admin:user:create
–admin-user=’admin’
–admin-password=’A@d_min202!’
–admin-email=’[email protected]’
–admin-firstname=’Admin’
–admin-lastname=’lname’
3 – Magento Install And Uninstall Command
Installing the Magento application using the Command Line :
php bin/magento setup:install
Uninstalling the Magento application using the Command Line :
php bin/magento cache:flush
Flush cache with specific type using the Command Line :
php bin/magento cache:flush cache_type
Cache status Using Command Line :
php bin/magento cache:status
Enable cache using the Command Line :
php bin/magento cache:enable
Enable Cache with specific type Using Command Line :
php bin/magento cache:enable cache_type
Disable cache using the Command Line :
php bin/magento cache:disable
Disable Cache with specific type Using Command Line :
php bin/magento cache:enable cache_type
5 – Delpoy Commands
Static Content Deploy Using Command Line (Use -f for force deploy on 2.2.x or later) :
php bin/magento setup:static-content:deploy
Static Content Deploy For Particular Language Using Command Line :
php bin/magento setup:static-content:deploy en_US
Deploy for Magento backend theme using the Command Line :
php bin/magento setup:static-content:deploy –theme=”Magento/backend”
Static content deploy for specific themes using the Command Line :
php bin/magento setup:static-content:deploy –theme Magento/Luma –theme Magento/porto
Exclude themes on static content deploy and does not minify HTML files using the Command Line :
php bin/magento setup:static-content:deploy en_US –exclude-theme Magento/Luma–no-html-minify
6 – Reindexing Commands
Reindexing using the Command Line :
php bin/magento indexer:reindex
List of indexers using the Command Line :
php bin/magento indexer:info
indexer status using the Command Line :
php bin/magento indexer:status
Reset indexer status to invalid using the Command line :
php bin/magento indexer:reset
Show the mode of all indexers using the Command Line :
php bin/magento indexer:show-mode
7 – Compilation Command
Compilation using the Command Line :
php bin/magento setup:di:compile
8 – Mode Commands
Check current mode using the Command line :
php bin/magento deploy:mode:show
Set developer mode using the Command Line :
php bin/magento deploy:mode:set developer
Set production mode using the Command Line :
php bin/magento deploy:mode:set production
9 – Cron Commands
Set Magento crontab using the Command Line :
php bin/magento cron:install –force
View all crontab using the Command Line :
crontab -l (L)
Run jobs by schedule using the Command Line :
php bin/magento cron:run
Remove Magento crontab using the Command Line :
php bin/magento cron:remove
10 – Module Commands
See all modules status using the Command Line :
php bin/magento module:status
Enable module using the Command Line :
php bin/magento module:enable VendorName_ModuleName
Disable module using the Command Line :
php bin/magento module:disable VendorName_ModuleName
Uninstall module using the Command Line :
php bin/magento module:uninstall VendorName_ModuleName
11 – Maintenance Mode Commands
Enable maintenance mode using the Command Line :
php bin/magento maintenance:status
Disable maintenance mode using the Command Line :
php bin/magento maintenance:disable
Check maintenance mode status using the Command Line :
php bin/magento maintenance:status
Clear the list of IPs using the Command Line :
php bin/magento maintenance:enable –ip=none
Enable maintenance mode for all clients except specific IPs :
php bin/magento maintenance:enable –ip=127.0.0.1 –ip=127.0.0.2
Allow IP on maintenance mode using the Command Line :
php bin/magento maintenance:allow-ips –ip=127.0.0.1 –ip=127.0.0.2
