Introduction to Magento2 Command Line Interface (CLI)

Introduction to Magento2 Command Line Interface (CLI)

Magento2 is the latest version of Magento, a CMS for e-commerce websites. It is significantly different from the previous Magento 1.x editions. Magento2 Command Line Interface is quite useful in performing various operations such as installations and configuration tasks.

It can be accessed from the PHP file /bin/magento’. This single PHP file can be used to perform a variety of tasks on your Magento.
Magento2

Magento CLI

Use the following command to list all the available commands for magento-cli.

php magento list

 

The output would look like the below image

Magento2

Magento Cache

Use the following commands to perform operations on Magento cache.

php magento cache:status # To view the current status of all cache types, i.e, 1 for enabled and 0 for disabled types.
php magento cache:enable [type] # To enable a cache type.
php magento cache:disable [type] # To disable a cache type.
php magento cache:clean [type] ... [type] # To clean a cache type.
php magento cache:flush [type] ... [type] # To flush a cache type.

 

Magento2

Magento2

Magento2

Cleaning the cache deletes all items from the enabled cache types only.

Flushing the cache purges the cache storage.

If you do not specify type[s], it will clean/flush every cache types.

Indexer

Use the following commands to perform operations on Magento indexer.


php magento indexer:info # To view the list of indexers.

php magento indexer:status [indexer] # To view the current status of an indexer.

php magento indexer:reindex [indexer] # To reindex an indexer.

Magento2

Magento2

Magento2

Omit [indexer] to perform operation on all the indexers.

The Magento 2 indexer has 2 modes, 'realtime' and 'schedule'.

  • Realtime ( updated on save) : Indexed data is updated as soon as the change is made in the Admin panel.
  • Schedule ( update by schedule ) : Data is indexed according to a schedule set by your Magento cron.

Use the following command to view the current configuration.


php magento indexer:show-mode [indexer]

Magento2

To change mode,  use the following command.


php magento indexer:set-mode {realtime|schedule} [indexer]

Magento2

Code Compiler

To compile Magento code, use the following command if Magento has one website and store.


php magento setup:di:compile

For Magento with multiple stores and websites , i.e, more than one independent Magento applications.


php magento setup:di:compile-multi-tenant

Magento2

Maintenance Mode

Use the following command to enable maintenance mode


php magento maintenance:enable

You can also use the following commands to exempt IP addresses from maintenance mode. Users with the exempt IP addresses will get the normal website.


php magento maintenance:enable [--ip= ... --ip=]

or


php magento maintenance:allow-ips [ .. ] | [--none]

Use –none to clear the list.

Magento2

Modules

You can use the following commands to configure modules from CLI.

 

php module:uninstall  # For uninstalling Modules
php module:status # For viewing the enabled and disabled modules
php module:disable  # For disabling a module
php module:enable  # For enabling a module  

 

Magento2

Magento2

Magento2

You can use ‘ php magento module:disable –all ‘ to disable all modules and ‘ php magento module:enable –all ‘ to enable all modules.

Get 24/7 expert server management

References
http://devdocs.magento.com/guides/v2.0/install-gde/install-roadmap_cli.html
http://devdocs.magento.com/guides/v2.0/config-guide/bk-config-guide.html

The post Introduction to Magento2 Command Line Interface (CLI) appeared first on SupportSages – Your IT Infrastructure partner !!.