Magento 2 Modes

Another major change brought about in Magento 2 is the introduction of modes which would assist with the Magento development process.

Magento 2 Modes

Today lets delve into the inner details of each modes in Magento 2 and also the steps of getting to know the current mode and how to switch modes via command-line commands. Each of the modes affects various configurations of the site's operations and also the performance. Magento 1 had no separate modes for development and production whereas Magento 2 introduces 3 new modes: Default, Developer and Production.

Default Mode:

The default mode is the one that Magento is configured initially when you install Magento unless you manually change it. This mode is a mix of both the Developer and the Production mode. This would also give you the ability to develop without compiling code and set of standardized configurations. In the default, mode errors are not thrown out on the screen and instead are logged in the server level. Though this makes it possible for debugging, it is not an ideal mode to be during the development of the site. Whenever a request is being made to the site, a symlink is created in the pub/static folder which depicts that full page cache is not completely utilized and the content produced to the user is a dynamic content that gets created on each request instead of pulling the data from the cache. The security risk involved with the presence of symlinks in the pub/static folder is that it gives the possibility of modifying the actual files on the server. When there are no symlinks, the modification to the files in the pub/statis folder would get removed away whenever we perform the static content deployment via the command line execution. Once you change the site from Default mode to some other mode, it is cumbersome to get it back to Default mode. The reason for this is being that Default mode is not meant for a long time use and it is only to help launch sites.

Developer Mode:

As it says, it is a mode with which we should perform all the development works. It is also to be noted that the sites would start work slow in this mode both on Frontend as well as Backend but it automatically compiles code and does more advanced logging and debugging capabilities than the Default and Production mode. Caching cant be used during the Development mode as it is typically disabled and this results in a lack of utilization of the pub/static folder thereby accounting to extremely low site loading. When you enable the Developer mode, all the errors that appear are displayed in the error handler than getting logged in the log files. If an exception occurs, the occurrence of exception is displayed with the exception number which can be viewed by opening the log file in the var folder. The exception number that is getting displayed would be the name of the log file. The displaying of exceptions abruptly on the browsers paves way for faster debugging of the issues.

Production Mode:

This is the mode in which all the Magento 2 live sites should be configured and the reason being that it fully utilizes caching. The pub folder is fully built and used in order to load the class files and render content as quick as possible. The Production mode does optimization to deliver smooth and efficient loading of the website for exceptional customer experience. The only downside of the Production mode is that debugging is very difficult as all the exceptions and errors are suppressed from showing to the users and are logged on at the server level. Whenever we make the site from Default or Developer mode to Production mode, we must make sure that we execute the Static Content Deployment and DI Compilation so that the pub/static folder gets loaded up. The Production mode also makes the site more secure as symlinks are not being used. So even if any malicious code is injected into the pub/static folder files, those would get automatically removed whenever the next static content deployment is done.

Checking Site's Current Mode:

  1. Login to the server SSH using applications like Putty.
  2. Navigate to the root directory of the Magento installation using the cd command.
  3. Execute the following command:
    1. php bin/magento deploy:mode:show

Your terminal would display the current active mode of the website.

Changing Site's Mode:

  1. Login to the server SSH using applications like Putty.
  2. Navigate to the root directory of the Magento installation using the cd command.
  3. Execute the following commands based on which mode you would like to switch:
    1. Developer Mode : php bin/magento deploy:mode:set developer
    2. Production Mode: php bin/magento deploy:mode:set production
    3. Default Mode: php bin/magento deploy:mode:set default

Final Note:

Whenever you are installing Magento 2, make sure to switch it to the Developer mode for carrying out all the development works or to the Production mode if you are going to make the site live. Do not do much of development work in the Default mode as performing development work in the Default mode for a prolonged time would result in lot of issues and conflicts when trying to switch to Production mode as we have to ultimately make the site live one day. Hence make sure to switch it to Production or Development mode as needed based on your intended purpose.

Write Your Comment

Only registered users can write comments. Please, log in or register