System modes available is one of the first basic things you need to know about when starting out with Magento 2. There are three primary Magento 2 modes including developer, production and default. The maintenance mode operates differently from the three others to exclusively prevent access to the system. In this tutorial, we will learn about different modes of Magento and how to enable developer mode to allow debugging in Magento
Magento 2 system modes understanding
1. Default Mode
Yes | No | |
Static File Catching | ✓ | |
Exceptions Displayed | ✓ | |
Exception Logged | ✓ | |
Negative Performance Impact | ✓ |
The Default Mode enable you to deploy the Magento application on a single server without settings changed. Default mode, however, is not optimized for production since it negatively influences on performance.
Exceptions are not displayed to the user but being written to log files. Errors are logged to var/log folder and never been shown to users. The file changes are not visible until the generated static view files are defined. It also hides custom X- Magento-* HTTP request and response headers.
In order to either deploy Magento application on more than one server or optimize server for production, it should be changed to other modes.
2. Developer Mode
Yes | No | |
Static File Catching | ✓ | |
Exceptions Displayed | ✓ | |
Exception Logged | ✓ | |
Negative Performance Impact | ✓ |
The Developer Mode should be selected as developing code for the Magento site. This mode is intended for development only.
The error messages are visible to the user. Static files are generated as being requested. Changes are visible immediately and uncaught exceptions are displayed in the browser. Developer Mode provides verbose logging and enables automatic code compilation. Debugging is enhanced. X- Magento-* HTTP request and response headers are shown. However, because of preceding, it results the slowest performance.
3. Production Mode
Yes | No | |
Static File Catching | ✓ | |
Exceptions Displayed | ✓ | |
Exception Logged | ✓ | |
Negative Performance Impact | ✓ |
The Production Mode is created for deployment on a production system and this mode is customer facing. Production Mode provides highest performance among three modes mentioned. Errors are logged into the file system so that they are never been displayed to the user. It also disables static view file materialization. Therefore, the static views are not generated as being called. They are deployed using the command line tool and stored in the static directory. Any changes to view files require running the deploy tool again. As using the command line tool, it’s not necessary to write access and the static directory can have read-only permissions as Magento docroot that is more secure.
As Development Mode should never be used on a live site, web user should instead generate static content in development mode and the use the deployer.php tool to push changes to production.
4. Maintenance Mode
When you do not want to make your site available to the public during updates or other changes with a 503 shown up, Maintenance Mode is an out- of- the- box feature that should be used in Magento 2.
This mode is controlled by the method Bootstrap::assertMaintenance(). A flag file (var/.maintenance.flag) is required to enable the mode.
It also allows to specify a group of people to have access to the site while the mode is employed by placing the associated IP in var/.maintenance.ip.
Current Mode Display
You should run this command as Magento file system owner. It’s the local user account on Magento server if you have private server or the user the provider gives you to log into the server if you share hosting.
Command line:
1 | magento deploy:mode:show |
A message is displayed:
1 | Current application mode: developer. |
Change to Developer Mode
1. Modes change
Comment line:
1 | magento deploy:mode:set {mode} [-s|--skip-compilation] |
In order to skip code compilation when you change to production mode, use
1 | --skip-compilation |
2. Change to Production Mode
In order to change to Developer Mode, first you should change to Production Mode
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | Enabled maintenance mode Requested languages: en_US === frontend -> Magento/luma -> en_US === ... more ... Successful: 1884 files; errors: 0 --- === frontend -> Magento/blank -> en_US === ... more ... Successful: 1828 files; errors: 0 --- === adminhtml -> Magento/backend -> en_US === ... more ... --- === Minify templates === ... more ... Successful: 897 files modified --- New version of deployed files: 1440461332 Static content deployment complete Gathering css/styles-m.less sources. Successfully processed LESS and/or SASS files CSS deployment complete Generated classes: Magento\Sales\Api\Data\CreditmemoCommentInterfacePersistor Magento\Sales\Api\Data\CreditmemoCommentInterfaceFactory Magento\Sales\Api\Data\CreditmemoCommentSearchResultInterfaceFactory Magento\Sales\Api\Data\CreditmemoComment\Repository Magento\Sales\Api\Data\CreditmemoItemInterfacePersistor ... more ... Compilation complete Disabled maintenance mode Enabled production mode. |
3. Change to Developer Mode
Step 1:
First, you should clear generated classes and Object Manager entities to prevent unexpected errors. Then, you can change the modes.
Step 2:
From the Production mode, delete contents of the var/generation and var/di directories:
1 | rm -rf <your Magento install dir>/var/di/* <your Magento install dir>/var/generation/* |
Set the mode using command line:
1 | magento deploy:mode:set developer |
You will see the following message:
1 | Switched to developer mode. |
After setting the mode, you should restart the web server for it to take effect.