Utilizing the CLI and Deployment Modes in Magento 2

Jul 5, 2018262Gennadiy Haritonov
Utilizing the CLI and Deployment Modes in Magento 2

Magento 2 allows you to perform multiple operations using the command line interface (CLI) and contains a large number of commands that allow you to quickly clear the cache, change the deployment mode, or reindex the required index.

CLI Commands

In order to use these commands, you should do the following:

  1. Login into your Magento 2 server via SSH as Magento file system owner:
  • $ ssh magento_user@server.com
  1. Change directory to Magento 2 installation directory:
  • $ cd /var/www/magento/

After that, we can use the Magento CLI like this: $ php bin/magento COMMAND.

For example, the list command will list the available actions: $ php bin/magento list.

Deployment Modes

Magento 2 can work in three possible modes:

  1. Default is the mode enabled by default. It should be used neither for development nor for production. It is the average between the developer and production modes.
  • Cached static files are enabled;
  • Exceptions are not displayed and are written into the log files.
  • X-Magento-* HTTP request and response headers are hidden.
  1. Developer is the mode intended for development. Static files are generated on demand. Also, this mode increases the amount of debug information.
  • Caching static files is disabled.
  • Exception and backtraces are displayed.
  • Automatic code compilation is enabled.
  • X-Magento-* HTTP request and response headers are enabled.
  • Low productivity.
  1. Production is used for working in the production environment. The highest speed of Magento 2 is achieved in this mode thanks to the generation of the necessary static files during the deployment and not on demand as in other modes.
  • Exceptions are written only into the log files and are not displayed.
  • Static files are given only from the cache (files are generated in advance using the $ php bin/magento setup:static-content:deploy command).
  • Automatic code compilation is disabled (it is performed in advance using the $ php bin/magento setup:di:compile command).

To find out the current deployment mode, use the following command:

$ bin/magento deploy:mode:show

Changing Deployment Mode

To change the current deployment mode, use the following command:

$ bin/magento deploy:mode:set {mode} [-s|–skip-compilation]

where:

  • {mode} is the necessary mode (developer or production);
  • –skip-compilation is an optional parameter that allows you to skip code compilation after changing the deployment mode.

If the deployment mode is changed, the var/cache, generated/metadata, generated/code, var/view_preprocessed, pub/static folders will be cleared except for the .htaccess files.



Post a new comment

top
BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *