Modes in Magento 2 Framework

There are four types of modes in the Magento 2 Framework.
Default, Developer, Production, and Maintenance

Default mode: As the name suggests, by default this mode is set on a fresh Magento installation. In this mode, Magento 2 applications can be deployed only on a single server. Also, changes to the settings are restricted in this mode. Errors/Exceptions will not be shown to the users in the frontend, they will be logged into the report files instead. Also, static view file caching is enabled. So creating static files first and then caching them has a performance impact. Hence, it is not optimized to be used in the production environment. 

Command to set an application to the default mode: php bin/Magento deploy:mode:set default 

Developer mode: As the name suggests, this mode is used for all the development tasks. This mode displays errors/exceptions in the browser rather than log them in the files. The developer mode slows the frontend and admin as static view files are not cached, but written to pub/static every time they are called from the request. It helps to debug faster than any other modes as it throws exceptions directly to the handler, rather than logging it. 

Command to set an application to the developer mode: php bin/magento deploy:mode:set developer 

Production mode: As the name suggests, this mode is used for all the live sites. It offers the best end-user experience. In this mode, all the static files are fully cached. Errors/Exceptions are never displayed to the end-users. They are logged in the files. So, it is quite difficult to debug in the production mode. Among all other modes, this is the most secure mode. 

Command to set an application to the production mode: php bin/magento deploy:mode:set production 

Maintenance mode: As the name suggests, this mode is used to show that the site is in maintenance. It makes the live site offline while updates to the site are being uploaded and configured. In maintenance mode, the site redirects to the “Service Temporarily Unavailable” page. We can create our custom maintenance page according to the theme of the site. Using this mode, we can allow visitors with certain IP addresses to view the site normally. 

To detect maintenance mode: File var/.maintenance.flag is used to detect whether maintenance mode is on or not. If a file exists, maintenance mode is enabled. File var/.maintenance.ip contains the list of the ip addresses. 

Commands:

To know maintenance status: php bin/magento maintenance:status 

To enable maintenance mode: php bin/magento maintenance:enable 

To disable maintenance mode: php bin/magento maintenance:disable 

To exempt from maintenance mode, use –ip=<ip address>: 

php bin/magento maintenance:enable  [–ip=<ip address> … –ip=<ip address>] | [ip=none] 

php bin/magento maintenance:disable   [–ip=<ip address> … –ip=<ip address>] | [ip=none] 

E.g. To enable maintenance mode except ip address “127.0.0.1”, run: php bin/magento maintenance:enable –ip=127.0.0.1 

To allow certain ip addresses: php bin/magento maintenance:allow-ips <ip address> .. <ip address> [–none] 

This blog is written by , Yash Shah – Sr. Software Engineer at Tridhya Innovation

CategoriesTechnologyTags

Leave a Reply

Your email address will not be published. Required fields are marked *