Magento 2 Command Line Tool (/bin/magento)
Since Magento 2 provides a very useful implementation of Symfony’s Console component, you can easily perform tons of important actions from a command line interface. It is possible to reindex, clean cache, generate code, create database backups, and run other commands with the help of this instrument. Moreover, you can easily enhance the existing solution with your own commands aimed at your Magento 2 extensions. Below, I explain how to use Magento 2 CLI tool and what commands to run.
Table of contents
- 1 Admin Magento 2 CLI commands
- 2 Cache Magento 2 CLI commands
- 3 Cron Magento 2 CLI commands
- 4 Developer Magento 2 CLI commands
- 5 i18n Magento 2 CLI commands
- 6 Indexer Magento 2 CLI Commands
- 7 Framework Magento 2 CLI Commands
- 8 Maintenance Magento 2 CLI Commands
- 9 Module Magento 2 CLI Commands
- 10 Setup Magento 2 CLI Commands
How to Run Magento 2 Command Line Tool from Magento 2 Root Folder
php bin/magento
The following post contains a list of commands (magento help <command>) with all possible use cases and parameters. Such command groups as Admin do not have any extended info, as it doesn’t make sense, since a command displays some info itself and there are no parameters to be passed.
vagrant@mage2:/vagrant/data/magento2/bin$ php magento
Magento CLI version 1.0.0-beta
Usage:
command [options] [arguments]
Options:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
--help (-h) Display this help message --quiet (-q) Do not output any message --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debugging --version (-V) Display an application version --ansi Force ANSI output --no-ansi Disable ANSI output --no-interaction (-n) Do not ask any interactive question |
Available commands:
1 2 3 |
help Displays help for a command list Lists commands |
admin
1 |
admin:user:create Creates an administrator |
cache
1 2 3 4 5 6 7 8 9 |
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 Checks cache status |
catalog
1 |
catalog:images:resize Creates resized product images |
cron
1 |
cron:run Runs jobs by schedule |
dev
1 2 3 4 5 |
dev:css:deploy Collects, processes and publishes source LESS files dev:tests:run Runs tests dev:xml:convert Converts XML file using XSL style sheets |
i18n
1 2 3 4 5 |
i18n:collect-phrases Discovers phrases in the codebase i18n:pack Saves language package i18n:uninstall Uninstalls language packages |
indexer
1 2 3 4 5 6 7 8 9 |
indexer:info Shows allowed Indexers indexer:reindex Reindexes Data indexer:set-mode Sets index mode type indexer:show-mode Shows Index Mode indexer:status Shows status of Indexer |
info
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
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-Magento 2 modules Shows number of dependencies between Magento 2 modules info:dependencies:show-Magento 2 modules-circular Shows number of circular dependencies between Magento 2 modules info:language:list Displays the list of available language locales info:timezone:list Displays the list of available timezones |
maintenance
1 2 3 4 5 6 7 |
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
1 2 3 4 5 6 7 |
module:disable Disables specified Magento 2 modules module:enable Enables specified Magento 2 modules module:status Displays status of Magento 2 modules module:uninstall Uninstalls Magento 2 modules installed by composer |
setup
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
setup:backup Takes backup of Magento Application code base, media and database setup:config:set Creates or modifies the deployment configuration setup:cron:run Runs cron job scheduled for setup application setup:db-data:upgrade Installs and upgrades data in the DB setup:db-schema:upgrade Installs and upgrades the DB schema setup:db:status Checks if DB schema or data requires upgrade setup:di:compile Generates DI configuration and all non-existing interceptors and factories setup:di:compile-multi-tenant Generates all non-existing proxies and factories, and pre-compile class definitions, inheritance information and plugin definitions setup:install Installs the Magento application setup:performance:generate-fixtures Generates fixtures setup:rollback Rolls back Magento Application codebase, media and database setup:store-config:set Installs the store configuration setup:uninstall Uninstalls the Magento application setup:upgrade Upgrades the Magento application, DB data, and schema |
theme
1 |
theme:uninstall Uninstalls theme |
Admin Magento 2 CLI commands
admin:user:create
Creates a Magento administrator user account
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
Usage: admin:user:create [--admin-user="..."] [--admin-password="..."] [--admin-email="..."] [--admin-firstname="..."] [--admin-lastname="..."] [--magento-init-params="..."] Options: --admin-user (Required) Admin user --admin-password (Required) Admin password --admin-email (Required) Admin email --admin-firstname (Required) Admin first name --admin-lastname (Required) Admin last name --magento-init-params Add to any command to customize Magento initialization parameters For example: "MAGE_MODE=developer&MAGE_DIRS[base][path]=/var/www/example.com&MAGE_DIRS[cache][path]=/var/tmp/cache" --help (-h) Display this help message --quiet (-q) Do not output any message --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug --version (-V) Display this application version --ansi Force ANSI output --no-ansi Disable ANSI output --no-interaction (-n) Do not ask any interactive question |
Cache Magento 2 CLI commands
cache:status
With this command you can see a list of all Magento 2 caches, each of them can be used for such cache management commands as clean or disable.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
Current status: config: 1 layout: 1 block_html: 1 view_files_fallback: 1 viewfiles_preprocessing: 1 collections: 1 db_ddl: 1 eav: 1 full_page: 1 translate: 1 config_integration: 1 config_integration_api: 1 config_webservice: 1 |
cache:clean
Cleans Magento 2 cache by type or all cache complete.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Usage: cache:clean [--all] [--bootstrap="..."] [types1] ... [typesN] Arguments: types List of cache types, space separated. If omitted, all caches will be affected Options: --all All cache types --bootstrap add or override parameters of the bootstrap |
cache:disable
Disables Magento 2 specific cache types or all cache complete.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Usage: cache:disable [--all] [--bootstrap="..."] [types1] ... [typesN] Arguments: types List of cache types, space separated. If omitted, all caches will be affected Options: --all All cache types --bootstrap add or override parameters of the bootstrap |
cache:enable
Enable Magento 2 specific cache types or all cache complete
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Usage: cache:enable [--all] [--bootstrap="..."] [types1] ... [typesN] Arguments: types List of cache types, space separated. If omitted, all caches will be affected Options: --all All cache types --bootstrap add or override parameters of the bootstrap |
cache:flush
Flushes Magento 2 cache storage
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Usage: cache:flush [--all] [--bootstrap="..."] [types1] ... [typesN] Arguments: types List of cache types, space separated. If omitted, all caches will be affected Options: --all All cache types --bootstrap add or override parameters of the bootstrap |
Cron Magento 2 CLI commands
cron:run
Runs specific cron job in Magento 2 system
1 2 3 4 5 6 7 |
Usage: cron:run [--group="..."] [--bootstrap="..."] Options: --group Run jobs only from specified group |
Developer Magento 2 CLI commands
dev:css:deploy
Collects, processes, and publishes source LESS files
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
Usage: dev:css:deploy [--locale="..."] [--area="..."] [--theme="..."] type [file1] ... [fileN] Arguments: type Type of dynamic stylesheet language: [less] file Files to pre-process (file should be specified without extension) (default: ["css/styles-m"]) Options: --locale Locale (default: "en_US") --area Area, one of [frontend|adminhtml|doc] (default: "frontend") --theme Theme in format Vendor/theme (default: "Magento/blank") |
dev:tests:run
Runs Magento 2 tests.
1 2 3 4 5 6 7 |
Usage: dev:tests:run [type] Arguments: type Type of test to run. Available types: all, unit, integration, integration-all, static, static-all, integrity, legacy, default (default: "default") |
dev:xml:convert
Converts XML file using XSL style sheets
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Usage: dev:xml:convert [-o|--overwrite] xml-file processor Arguments: xml-file Path to XML file that going to be transformed processor Path to XSL style sheet that going to be applied to XML file Options: --overwrite (-o) Overwrite XML file |
i18n Magento 2 CLI commands
i18n:collect-phrases
Discovers phrases in the codebase.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Usage: i18n:collect-phrases [-o|--output="..."] [-m|--magento] directory Arguments: directory Directory path to parse Options: --output (-o) Path (including filename) to an output file. With no file specified, defaults to stdout. --magento (-m) Use the --magento parameter to specify the directory as the Magento root directory. Omit the parameter if the directory is not the Magento root directory. |
i18n:pack
Saves Magento 2 language package.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
Usage: i18n:pack [-m|--mode="..."] [-d|--allow-duplicates] source pack locale Arguments: source Path to source dictionary file with translations pack Path to language package locale Target locale for dictionary, for example "de_DE" Options: --mode (-m) Save mode for dictionary - "replace" - replace language pack by new one - "merge" - merge language packages, by default "replace" (default: "replace") --allow-duplicates (-d) Use the --allow-duplicates parameter to allow saving duplicates of translate. Otherwise omit the parameter. |
i18n:uninstall
Uninstalls language packages.
1 2 3 4 5 6 7 8 9 10 11 |
Usage: i18n:uninstall [-b|--backup-code] package1 ... [packageN] Arguments: package Language package name Options: --backup-code (-b) Take code and configuration files backup (excluding temporary files) |
Indexer Magento 2 CLI Commands
indexer:info
Shows allowed Indexers – get each index names and use them to set mode and reindex.
indexer:reindex
Reindexes Data
1 2 3 4 5 6 7 8 9 10 11 |
Usage: indexer:reindex [-a|--all] [index1] ... [indexN] Arguments: index List of Indexes Options: --all (-a) All Indexes |
indexer:set-mode
Sets index mode type.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Usage: indexer:set-mode [-a|--all] [mode] [index1] ... [indexN] Arguments: mode Indexer mode type [realtime|schedule] index List of Indexes Options: --all (-a) All Indexes |
indexer:show-mode
Shows Index Mode
1 2 3 4 5 6 7 8 9 10 11 |
Usage: indexer:show-mode [-a|--all] [index1] ... [indexN] Arguments: index List of Indexes Options: --all (-a) All Indexes |
indexer:status
Shows status of Indexer, or –all Magento 2 indexers
Framework Magento 2 CLI Commands
info:dependencies:show-Magento 2 modules
Shows number of dependencies between Magento 2 modules.
1 2 3 4 5 6 7 8 9 |
Usage: info:dependencies:show-Magento 2 modules [-d|--directory="..."] [-o|--output="..."] Options: --directory (-d) Path to base directory for parsing (default: "/vagrant/data/magento2") --output (-o) Report filename (default: "Magento 2 modules-dependencies.csv") |
info:dependencies:show-Magento 2 modules-circular
Shows number of circular dependencies between modules.
1 2 3 4 5 6 7 8 9 |
Usage: info:dependencies:show-Magento 2 modules-circular [-d|--directory="..."] [-o|--output="..."] Options: --directory (-d) Path to base directory for parsing (default: "/vagrant/data/magento2") --output (-o) Report filename (default: "Magento 2 modules-circular-dependencies.csv") |
Maintenance Magento 2 CLI Commands
1 |
maintenance:allow-ips |
Sets maintenance mode exempt IPs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Usage: maintenance:allow-ips [--none] [--magento-init-params="..."] [ip1] ... [ipN] Arguments: ip Allowed IP addresses Options: --none Clear allowed IP addresses --magento-init-params Add to any command to customize Magento initialization parameters For example: "MAGE_MODE=developer&MAGE_DIRS[base][path]=/var/www/example.com&MAGE_DIRS[cache][path]=/var/tmp/cache" |
maintenance:disable
Disables maintenance mode.
1 2 3 4 5 6 7 8 9 10 11 |
Usage: maintenance:disable [--ip="..."] [--magento-init-params="..."] Options: --ip Allowed IP addresses (use 'none' to clear allowed IP list) (multiple values allowed) --magento-init-params Add to any command to customize Magento initialization parameters For example: "MAGE_MODE=developer&MAGE_DIRS[base][path]=/var/www/example.com&MAGE_DIRS[cache][path]=/var/tmp/cache" |
maintenance:enable
Enables maintenance mode.
1 2 3 4 5 6 7 8 9 10 11 |
Usage: maintenance:enable [--ip="..."] [--magento-init-params="..."] Options: --ip Allowed IP addresses (use 'none' to clear allowed IP list) (multiple values allowed) --magento-init-params Add to any command to customize Magento initialization parameters For example: "MAGE_MODE=developer&MAGE_DIRS[base][path]=/var/www/example.com&MAGE_DIRS[cache][path]=/var/tmp/cache" |
maintenance:status
Displays maintenance mode status
1 2 3 4 5 6 7 8 9 |
Usage: maintenance:status [--magento-init-params="..."] Options: --magento-init-params Add to any command to customize Magento initialization parameters For example: "MAGE_MODE=developer&MAGE_DIRS[base][path]=/var/www/example.com&MAGE_DIRS[cache][path]=/var/tmp/cache" |
Module Magento 2 CLI Commands
module:disable
Disables specified Magento 2 modules.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
Usage: module:disable [-f|--force] [--all] [-c|--clear-static-content] [--magento-init-params="..."] [module1] ... [moduleN] Arguments: module Name of the module Options: --force (-f) Bypass dependencies check --all Disable all Magento 2 modules --clear-static-content (-c) Clear generated static view files. Necessary, if the module(s) have static view files --magento-init-params Add to any command to customize Magento initialization parameters For example: "MAGE_MODE=developer&MAGE_DIRS[base][path]=/var/www/example.com&MAGE_DIRS[cache][path]=/var/tmp/cache" |
module:enable
Enables specified Magento 2 modules.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
Usage: module:enable [-f|--force] [--all] [-c|--clear-static-content] [--magento-init-params="..."] [module1] ... [moduleN] Arguments: module Name of the module Options: --force (-f) Bypass dependencies check --all Enable all modules --clear-static-content (-c) Clear generated static view files. Necessary, if the module(s) have static view files --magento-init-params Add to any command to customize Magento initialization parameters For example: "MAGE_MODE=developer&MAGE_DIRS[base][path]=/var/www/example.com&MAGE_DIRS[cache][path]=/var/tmp/cache" |
module:status
Displays status of Magento 2 modules.
1 2 3 4 5 6 7 8 9 |
Usage: module:status [--magento-init-params="..."] Options: --magento-init-params Add to any command to customize Magento initialization parameters For example: "MAGE_MODE=developer&MAGE_DIRS[base][path]=/var/www/example.com&MAGE_DIRS[cache][path]=/var/tmp/cache" |
module:uninstall
Uninstalls Magento 2 modules installed by composer.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
Usage: module:uninstall [-r|--remove-data] [--backup-code] [--backup-media] [--backup-db] [-c|--clear-static-content] [--magento-init-params="..."] module1 ... [moduleN] Arguments: module Name of the module Options: --remove-data (-r) Remove data installed by module(s) --backup-code Take code and configuration files backup (excluding temporary files) --backup-media Take media backup --backup-db Take complete database backup --clear-static-content (-c) Clear generated static view files. Necessary, if the module(s) have static view files --magento-init-params Add to any command to customize Magento initialization parameters For example: "MAGE_MODE=developer&MAGE_DIRS[base][path]=/var/www/example.com&MAGE_DIRS[cache][path]=/var/tmp/cache" |
Setup Magento 2 CLI Commands
setup:backup
Takes backup of Magento Application code base, media and database
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Usage: setup:backup [--code] [--media] [--db] [--magento-init-params="..."] Options: --code Take code and configuration files backup (excluding temporary files) --media Take media backup --db Take complete database backup --magento-init-params Add to any command to customize Magento initialization parameters For example: "MAGE_MODE=developer&MAGE_DIRS[base][path]=/var/www/example.com&MAGE_DIRS[cache][path]=/var/tmp/cache" |
setup:config:set
Creates or modifies the deployment configuration of Magento 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
Usage: setup:config:set [--backend-frontname="..."] [--key="..."] [--session-save="..."] [--definition-format="..."] [--db-host="..."] [--db-name="..."] [--db-user="..."] [--db-engine="..."] [--db-password="..."] [--db-prefix="..."] [--db-model="..."] [--db-init-statements="..."] [-s|--skip-db-validation] [--magento-init-params="..."] Options: --backend-frontname Backend frontname --key Encryption key --session-save Session save location --definition-format Type of definitions used by Object Manager --db-host Database server host --db-name Database name --db-user Database server username --db-engine Database server engine --db-password Database server password --db-prefix Database table prefix --db-model Database type --db-init-statements Database initial set of commands --skip-db-validation (-s) If specified, then db connection validation will be skipped --magento-init-params Add to any command to customize Magento initialization parameters For example: "MAGE_MODE=developer&MAGE_DIRS[base][path]=/var/www/example.com&MAGE_DIRS[cache][path]=/var/tmp/cache" |
setup:cron:run
Runs cron job scheduled for setup application
To be continue..
We will keep updating this post as any changes and updates related to Magento 2 Command line tool interface are available.
More Magento 2 features, tips, and rumours