Introducing Magento 2 Command Line ultility (CLI)

Magento 2.0 has a Command-Line Interface (CLI) to help developers manage installation and configuration tasks. It saves a lot of time for developers during the development time. The new command-line interface can do many things, such as:

  • Installing Magento
  • Clearing the cache
  • Managing indexes, including reindexing
  • Configuring and running cron
  • Compiling code
  • Setting the Magento mode
  • Setting the URN highlighter
  • Creating dependency reports
  • Creating translation dictionaries and language packages
  • Deploying static view files
  • Creating symlinks to LESS files
  • Running unit tests
  • Converting layout into XML files
  • Generating data for performance testing
  • Creating CSS from LESS (CSS real-time compilation)

Let’s see how this feature works.

How to use Magento 2 CLI

To work with Magento 2 CLI, first you need to check if php_cli package is installed to your Magento 2 instance following steps below:

  1. Open a terminal (Linux, OS X) or command prompt (Windows) and navigate to the root directory of your local Magento 2 installation
    Then, you run the following command in the Terminal: php bin/magento
  2. If you see all available commands of the command-line utility, the php_cli package has been installed properly.

Magento 2 CLI

Available commands of the command-line utility confirms php_cli has been installed

If not, you will need to install php-cli package. If you use an Ubuntu system, you can enter the following command at a terminal prompt to install php-cli:
sudo apt install php-cli

Useful Magento 2 CLI commands

I will share you the most common command lines that you will be using while working with Magento 2.

cache:clean Cleans cache type(s)
cache:disable Disables cache type(s)
cache:enable Enables cache type(s)
cache:flush Flushes cache storage used by cache type(s)
cache:status Check cache status


deploy:mode:set Set application mode
deploy:mode:show Displays current application mode


indexer:info Shows allowed Indexers
indexer:reindex Reindexes Data
indexer:reset Resets indexer status to invalid
indexer:set-mode Sets index mode type
indexer:show-mode Shows Index Mode
indexer:status Shows status of Indexer


dev:di:info Provides information on Dependency Injection configuration for the Command
dev:query-log:disable Disable DB query logging
dev:query-log:enable Enable DB query logging
dev:source-theme:deploy Collects and publishes source files for theme
dev:template-hints:disable Disable frontend template hints. A cache flush might be required.
dev:template-hints:enable Enable frontend template hints. A cache flush might be required.
dev:tests:run Runs tests
dev:urn-catalog:generate Generates the catalog of URNs to *.xsd mappings for the IDE to highlight xml.
dev:xml:convert Converts XML file using XSL style sheets


maintenance:allow-ips Sets maintenance mode exempt IPs
maintenance:disable Disables maintenance mode
maintenance:enable Enables maintenance mode
maintenance:status Displays maintenance mode status


module:disable Disables specified modules
module:enable Enables specified modules
module:status Displays status of modules
module:uninstall Uninstalls modules installed by composer


i18n:collect-phrases Discovers phrases in the codebase
i18n:pack Saves language package
i18n:uninstall Uninstalls language packages


info:adminuri Displays the Magento Admin URI
info:backups:list Prints list of available backup files
info:currency:list Displays the list of available currencies
info:dependencies:show-framework Shows number of dependencies on Magento framework
info:dependencies:show-modules Shows number of dependencies between modules
info:dependencies:show-modules-circular Shows number of circular dependencies between


We strongly advise you to play more with the Magento 2 command-line utility. With a wide collection of handy command lines, you can easily perform important installation and configuration tasks (you will be using some of them when working with our Magento 2 extensions). Moreover, it is possible to extend Magento 2 built-in command-line tool with custom commands following Magento guideline here, if you choose to.

Written By