Usefull Magento 2 CLI commands

Usefull SSH Commands for Magento 2

If you are not familiar with the SSH / CLI commands for Magento 2 you likely constantly browse the web to find the commands to use for certain tasks. To save your time, We have created a list of most useful commands for Magento 2.

To use these commands you will need to have SSH access to your server or use the Command Line for local access.

Sometimes when using these commands you can have issues with the correct PHP version for CLI. To check this just type

php -v

This command show you what PHP version is used for CLI. If this is not correct version thane ask you server administratot to correct this or you can also force the CLI to use the correct version by adding the php directory to your command like this:

<path to your php> bin/magento setup:upgrade

Setup Upgrade

php bin/magento setup:upgrade

If you don't want to remove pub/static files while installing/updating database then use following command.

php bin/magento setup:upgrade --keep-generated

Cache Clean

php bin/magento cache:clean

Cache Flush

php bin/magento cache:flush

View cache status

php bin/magento cache:status

Enable Cache

php bin/magento cache:enable [cache_type]

Disable Cache

php bin/magento cache:disable [cache_type]

Static Content Deploy (Use -f for force deploy on 2.2.x or later)

php bin/magento setup:static-content:deploy

Static Content Deploy For Particular Language

php bin/magento setup:static-content:deploy en_US

Static Content Deploy For Magento Backend Theme (Working on 2.1.1 or later)

php bin/magento setup:static-content:deploy --theme="Magento/backend"

Static Content Deploy For Specific Themes (Working on 2.1.1 or later)

php bin/magento setup:static-content:deploy --theme Magento/luma --theme Magento/second_theme


php bin/magento indexer:reindex

View the 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

See all modules Status

php bin/magento module:status

Enable module

php bin/magento module:enable Namespace_Module

Disable module

php bin/magento module:disable Namespace_Module

Uninstall Module

php bin/magento module:uninstall Namespace_Module

Check Current Mode

php bin/magento deploy:mode:show

Change To Developer Mode

php bin/magento deploy:mode:set developer

Change To Production Mode

php bin/magento deploy:mode:set production

Unlock Admin User

php bin/magento admin:user:unlock adminusername

Enable Maintenance Mode

php bin/magento maintenance:enable

Disable Maintenance Mode

php bin/magento maintenance:disable

Check Maintenance Mode Status

php bin/magento maintenance:status

Set Magento crontab

php bin/magento cron:install --force

Use --force to rewrite an existing Magento crontab.
To view the crontab, enter the following command as the Magento file system owner.

crontab -l

Remove Magento crontab

php bin/magento cron:remove