Magento2 comes with a powerful command line interface. It is possible to do a lot a lot of tasks like reindex, clean cache, generate code, create database backups just by typing in your terminal.

You run magento2 commands like this: php bin/magento command [options] [arguments]. In order to be quicker you can export that path. So you can open your terminal sudo nano ~/.bash_profile and add this line export PATH=$PATH:/Users/Username/sites/magento2/bin. Then restart your terminal. If you type magento -help now you should get a list of all commands. If you get an error saying “Permission denied”, then you should run chmod a+x /Users/Username/sites/magento2/bin/magento

Now every time you want to run a magento command you just type magento.

Here is a list of the most helpful commands (with the explanation in brackets):

1
2
3
4
5
6
7
8
magento cache:clean (flushes all caches)
magento indexer:reindex (reindexes)
magento setup:static-content:deploy (deploys static view files)
magento module:enable (enables specified module, i.e magento module:enable Company_Stockists)
magento setup:upgrade (upgrades the app, db and schema. This needs to run after every module install)
magento setup:backup (takes backup of Magento Application code base, media and database)
magento admin:user:create (creates an admin user, options required)
magento cron:run (run a specific cron, i.e cron:run merchant)

Some commands have required options, like admin:user:create. To see the options of a command you can run: magento admin:user:create -h and you’ll get:

1
2
3
4
5
6
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

So for the command to be successful, you may run it like this:

1
magento admin:user:create --admin-user claudiu --admin-password mypass123 --admin-email my@email.com --admin-firstname me --admin-lastname surname

Note that you cannot have semicolons ; or parentheses () inside your password.

Another useful command, but only for phpstorm users: magento dev:urn-catalog:generate .idea/misc.xml. This command will resolve URNs.

The full list of commands:

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
dmin
 admin:user:create                         Creates an administrator
 admin:user:unlock                         Unlock Admin Account
cache
 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
 catalog:images:resize                     Creates resized product images
cron
 cron:run                                  Runs jobs by schedule
customer
 customer:hash:upgrade                     Upgrade customer's hash according to the latest algorithm
deploy
 deploy:mode:set                           Set application mode.
 deploy:mode:show                          Displays current application mode.
dev
 dev:source-theme:deploy                   Collects and publishes source files for theme.
 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
i18n
 i18n:collect-phrases                      Discovers phrases in the codebase
 i18n:pack                                 Saves language package
 i18n:uninstall                            Uninstalls language packages
indexer
 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
 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 modules
 info:language:list                        Displays the list of available language locales
 info:timezone:list                        Displays the list of available timezones
maintenance
 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
 module:disable                            Disables specified modules
 module:enable                             Enables specified modules
 module:status                             Displays status of modules
 module:uninstall                          Uninstalls modules installed by composer
sampledata
 sampledata:deploy                         Deploy sample data modules
 sampledata:remove                         Remove all sample data packages from composer.json
 sampledata:reset                          Reset all sample data modules for re-installation
setup
 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:static-content:deploy               Deploys static view files
 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
 theme:uninstall                           Uninstalls theme