About Magento 2 modes: What are the different modes and how to set them?
One of the major difference between Magento 1 and Magento 2 is that Magento 2 webshops can run in different modes. The shop performance and speed varies between these 3 modes and each one of them is built for a different purpose, so it is important to use the correct mode while building and running a Magento 2 webshop. In this article, we will talk about these different Magento 2 modes and learn how to set them via SSH commands.
A Magento 2 webshop can be run in one of the following 3 modes:
- Default
- Developer
- Production
Default mode
This mode is the default setting on your new Magento 2 installation. It allows you to run your Magento application on a single server, without any changes required in the settings. In that, it is works somewhat between developer and production modes. However default mode is not ideal for production.
While default mode decreases the time to launch a Magento store when compared to the developer mode. It is not ideal for development phase as it cannot handle the new modifications as efficiently as the developer mode.
If you are looking to deploy the Magento application on several servers or if you want an optimised solution for production, choose one of the other available modes.
Developer mode
Deploy your Magento 2 application in this mode if you are looking to customise it (install themes or extensions, custom changes, etc.).
This mode is much slower than default and production modes. This is due to the fact that it automatically compiles code and because it enables enhanced debugging capabilities as compared to the other modes.
You will be able to see uncaught exceptions in the browser when using this mode, unlike an error number that shows up on the browser when using the other 2 modes. It also throws an exception when an event subscriber cannot be invoked.
To summarise, use this mode if you are a Magento developer working on building a Magento site.
Production mode
Production mode is intended for deploying your Magento application on a production system. This mode is optimised to work on production level, so exceptions will not be displayed in the browser and written to logs only. Your live Magento 2 webshop should be in production mode.
How to check your current deployment mode?
The following
command will display the current deployment mode from your Magento application root:
php bin/magento deploy:mode:show
How to change your deployment mode?
To change your deployment mode, run the following command from
your Magento application root:
php bin/magento deploy:mode:set {mode} [-s|--skip-compilation]
{mode} is required and can be either developer or production[-s|--skip-compilation] is an optional parameter you can use to skip compiling code when you set production mode.
Troubleshooting
While in production mode, your new changes may not reflect right away on webshop frontend. You need to
clear cache and re-deploy static content after you make any changes in the site.
You can use this command to clear cache
php bin/magento cache:clean
And then to re-deploy content you can give following command:
php bin/magento setup:static-content:deploy
If you want to deploy specific store content then you need to mention that:
php bin/magento setup:static-content:deploy fr_FR nl_NL en_US
For example here we have a shop with French, Dutch and
English stores.Also, if you want to run re-index from ssh, you can use following command:
bin/magento indexer:reindex