Magento 2 Command Line Interface: useful commands

Merchants that use Magento 2 know it has a console command line. However, not all of the newbies know how to use it all out. Here we have decided to share the knowledge and give some useful tips.

Looking to extend your Magento 2 functionality? Choose the extension that matches your current business needs.

How to work with Magento 2 Command Line Interface? What is the correct way to execute Magento CLI? commands

To use the CLI you will have to complete three simple steps.

Step 1: check Php_cli

  • Php_cli is installed to your Magento 2 by default with PHP. In case you don’t see php_cli, navigate to your Magento 2 root folder and type in: php bin/magento

If you see the list of commands, the php_cli has been installed correctly.
If you see the ‘Command not found’ error, there are tens of reasons some of which are considered here.
If the php bin/magento and other related commands are executed but you see multiple PHP errors like ‘PHP Parse error’. There is a strong possibility you use a wrong PHP version. To find a relevant version for your Magento follow the link.  You can simply check the current PHP version typing the php -v command into your command line. It may also occur that several PHP versions are to be available for your Magento.

  • Don’t forget to switch to the Magento 2 file system owner.

Step 2: most in-demand Magento 2 CLI commands

Common CLI commands

Command Meaning

php bin/magento cache:{enable|disable|clean|flush|status}

manage the cache;
php bin/magento setup:indexer:{status|show-mode|set-mode|reindex|info} manage the indexers;
php bin/magento cron:run use cron jobs;
php bin/magento setup:di:compile compile all non-existent proxies/factories; pre-compile class definitions, inheritance information, and plug-in definitions for one store and website. Do you want to learn more? Read all about permissions in our Magento 2 permissions & ownership in 3 modes post;
php bin/magento info:dependencies:{show-modules|show-modules-circular|show-framework} module dependencies, circular dependencies, Magento framework dependencies;
php bin/magento i18n:{collect-phrases|pack} generate a translation dictionary or a translation package. To generate a translation package for a definite module you can use a such-like command: php bin/magento i18n:collect-phrases -o app/code/Amasty/Rma/i18n/en_US.csv app/code/Amasty/Rma/ (in the described case, Amasty_Rma file will be generated);
php bin/magento setup:static-content:deploy deploy static view files;
php bin/magento dev:source-theme:deploy generate CSS from LESS
php bin/magento dev:tests:run run automated tests;
php bin/magento dev:xml:convert update your layout XML files to match the new Extensible Stylesheet Language Transformations (XSLT) stylesheet;
php bin/magento setup:perf:generate-fixtures generate data to use for performance testing;
php bin/magento sampledata:install install optional Magento sample data after you install the Magento application.


Haven’t you found a necessary command? Enter php bin/magento to display a complete list of commands:


See here to find any additional information.

Common arguments:

The arguments displayed on the screenshot are common for all commands. 


Step 3: use a necessary command

The commands can be added in one of the next ways:

  • php magento <command>- the command is used in case you are in root_site_path/bin; but if you are in the site root, use the next command: php bin/magento <command>
How can we help you?

Didn’t you find the answer to your question? We are always happy to help you out.