Magento CLI

Learn which are the most commonly used Magento CLI commands

In this tutorial we would provide information on the most used Magento CLI commands and how to execute them. The first thing you need to do is to connect to your account via SSH. Then switch to your Magento application's document root. If it is located in the primary domain of your account, you should go to the public_html/ folder of your account using the command below:

The Magento CLI binary should be executed with PHP cli. If you are in the public_html/ of your account, you should use the following command to run it:

After the path to the Magento binary (bin/magento), you should add the exact command you want to execute. For example - the command you should use to flush the application's cache is cache:flush. What you should execute in the Magento document root is as follows:

List commands

list - lists all available commands

Usage:

Help

To get more information on how a command should be executed and what are its available options, use --help after the command. For example to review the available options for the list command, execute the following:

You may add --help after any command to get more information about it.

Maintenance

There are 4 main commands that can help you manage the maintenance of your Magento store.

  • maintenance:status - this is the command you may use to check the maintenance status of your store
  • maintenance:disable - executing this one would deactivate maintenance mode
  • maintenance:enable - this one is used to activate maintenance mode
  • maintenance:allow-ips - this command is used to deactivate maintenance mode for a certain IP address. It requires additional parameter - your IP address. You should add it after the command as shown below:

where 0.0.0.0 should be the IP address you want to allow. If you want to add multiple IPs, separate them with a space.

To clear all allowed IP addresses, use --none as parameter:

Sampledata

There are 3 commands used to manage sample data:

  • sampledata:deploy - you should use this command to deploy sample data modules
  • sampledata:remove - this one's purpose is to remove all sample data packages from composer.json
  • sampledata:reset - execute this command to reset all sample data modules and re-install them

Admin actions

In case you forgot your admin user's username or password, you may easily create a new one by using the admin:user:create command. This one requires at least five additional parameters - username, password, email address, first and last name.

Usage:

where you should substitute USERNAME, PASSWORD, NAME, SURNAME and EMAIL with the necessary values.

Cache management

To flush your Magento application's cache, you should use the cache:flush command. Additionally, if you want to clear only certain types of cache, just add the type as a parameter after the command. For example, if you want to flush the full_page and config_webservice caches only, execute the command below:

To disable or enable caching for certain types, use the commands below:

  • cache:disable

  • cache:enable

Resize images

catalog:images:resize - this command is used to resize catalog images

Cron

To manually run the cron jobs for your application, execute the command below:

Indexer

  • indexer:info - using this one you may check the available indexes and their system name
  • indexer:status - you can use this command to check the status of the indexes
  • indexer:reindex - if executed without additional parameters, reindexes all indexes. If you want to run it for certain indexes, you should add their system names as parameters as shown below:

Modules

  • module:disable - disables the modules┬áspecified as parameters
  • module:enable - enables specified modules
  • module:status - displays status of modules
  • module:uninstall - uninstalls modules installed by composer

Usage (for the purpose of this tutorial we would disable, enable and uninstall a module named SY_Callback):

You may add multiple modules separated with a space.

Setup

  • setup:backup - takes backup of Magento Application code base, media or database and stores the backup in var/backups/. You should specify as additional parameters what the backup should contain. If you want to backup the code base, media and database, use the command below:

  • setup:db-data:upgrade - installs and upgrades data in the DB
  • setup:db-schema:upgrade - installs and upgrades the DB schema
  • setup:di:compile - generates DI configuration and all missing classes that can be auto-generated. You should run it during deployment of changes such as theme change.
  • setup:static-content:deploy - deploys static view files
  • setup:upgrade - upgrades the Magento application, DB data, and schema