All about application modes

Magento determines which code to run depending on where and when Magento is used. We can get the application mode by running:

bin/magento deploy:mode:show

Magento always comes with default mode enabled out of the box after an install.

Let's open up the Magento DevDocs at devdocs.magento.com.

They have some great documentation all around. Let's visit the Configuration Guide under Setup. Then we'll go to Magento application initialization, then About Magento modes. This will provide some more info on these modes.

The default mode should be looked at as a sort of demo mode rather than a real applicaiton mode. The defaults for this mode were made to make Magento work out of the box with little or no config changes, but is sort of a hybrid between developer and production modes. Because of the odd setup it's not recommended to run this mode anywhere other than to easily spin up store demos.

The next mode is developer. This app mode disables specific caches, and outputs errors to the browser for an easier dev workflow. Magento requires various code compilation processes in order to speed up requests, and dev mode enables this to happen automatically instead of needing to manually compile code. This is the mode we'll almost always want to do development in.

The next mode is production mode. This mode has some additional levels of caching and drastically speeds up web requests. It's not like developer mode, and requires the need to run scripts to manually compile and cache specific core areas of Magento. Debugging output, including displaying errors in the web browser is also disabled. Because of this, you'll never really want to run this mode in development unless you are trying to diagnose something really specific to production mode and your store, which is very uncommon.

The final option is maintenance mode which is used when a website is in production, and you would like to stop incoming web requests.. When this mode is toggled on, a file is made at var/.maintenance.flag which tells Magento to skip normal response processing and return a maintenance page. This mode will be toggled on only during certain code deployments to production, where you want to ensure new code is completely deployed before allowing access again.

We can use the bin/magento command line tool to set the application or deploy mode. In this tool is a deploy:mode:set option, and it accepts a single parameter being the app mode we want to enable. Let's toggle developer mode on to ensure it's set.

bin/magento deploy:mode:set developer

Once you are set to developer mode, there's little reason to ever change this mode again during development.

Discussion

0 comments