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:
- Login into your Magento 2 server via SSH as Magento file system owner:
- $ ssh [email protected]
- 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:
- 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.
- 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.
- 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.