Magento 2 Modes – How To Switch The Environment Mode & What They Each Do

Ok, so there’s some basic material you need to know when starting out with Magento 2, one being the system modes available.

There are 3 primary Magento 2 modes: developer, production, and default.

There is also a maintenance mode, which operates in a different way to exclusively prevent access to the system.

Key Features Of The Magento 2 System Modes

Developer Mode Production Mode Default Mode
Static File Caching
Exceptions Displayed
Exceptions Logged
Negative Performance Impact

Developer Mode

Exactly as it says on the tin, this mode should be chosen when you are developing code for your Magento site. Here’s why:

  • Error messages are visible to you
  • Static view files are generated every time they are requested
  • Cache is not used
  • Changes are immediately visible
  • Uncaught exceptions are displayed in the browser
  • Exceptions are thrown in the error handler
  • Exceptions are thrown whenever an event subscriber cannot be invoked
  • System logging in var/report is highly detailed in this mode.
  • Shows custom X-Magento-* HTTP request and response headers

This mode negatively impacts on performance and should not be used once in production for this reason.

Production Mode

Funnily enough, you should run Magento in Production mode once it is deployed to a production server and is customer facing. Here’s why:

  • Provides the highest performance
  • Errors are logged in the file system and are never displayed to the user
  • Static view file materialisation is disabled
    •  This means the static view files are not regenerated every time they are called, they are  deployed using the command line tool and stored in the pub/static directory.
    • Any changes to view files require running the deploy tool again.
    • The view files are deployed using the command line tool, this means the web user does not need to have write access, and the pub/static directory can have read-only permissions which is a more secure setup.
  • The Magento docroot has read-only permissions

As said before, development mode should never be used on a live site. So, when you need to make changes, you should instead generate static content in development and then use the deployer.php tool to push changes to production

Default Mode

This is the fallback mode and is how the Magento software operates if no other mode is specified.

  • Errors are logged to  var/reports and are never shown to a user
  • Static view files are materialized and then cached
    • View file changes are not visible until the generated static view files are cleared
  • Hides custom X-Magento-* HTTP request and response headers
  • This mode is not optimized for a production

Maintenance Mode

This is an out-of-the-box feature in Magento 2 that can be used when you want to make your site unavailable to the public during updates or other changes, a 503 is shown.

The method Bootstrap::assertMaintenance() controls this mode, and you have to create a flag file (var/.maintenance.flag) to enable the mode.

You can specify a group of people to have access to the site while this mode is employed by placing the associated IPs in var/.maintenance.ip.

Setting The Mode

Command Line

You can switch your Magento store mode using the following command in your black window:

magento deploy:mode:set [mode] [-s|--skip-compilation]

[mode] is required; it can be either developer or production

--skip-compilation is an optional parameter that skips code compilation when you change to production mode.

Web Server Environment

Apache web servers with mod_php support this method. The environment variables can be set in the main apache configuration or in the .htaccess.

If you are using an Apache system you can do the following:

  • Open Apache
  • Open the .htaccess file
  • Use the MAGE_MODE system environment variable to specify the mode as follows:
SetEnv MAGE_MODE [mode]

[mode] is required; it can be either default, developer or production

After setting the mode you will need to restart the web server for it to take effect.

php-fpm Environment

You can specify the mode in the php-fpm config or in the system environment in which the php-fpm is started.

In the php-fpm config file, the value can be set as follows:


[mode] is required; it can be either default, developer or production

Displaying The Current Mode

Command Line

You can view which mode you are in by using the following command in the black window:

magento deploy:mode:show

It will then show the following message:

Current application mode: [mode].

Learn more about Magento 2

The pool of resources for learning Magento 2 is growing every day, a great place to start is Magento U, the eCommerce university. You can even access Unit 1 of the for free here: Fundamentals of Magento 2 Development: Unit 1

Project Manager @iwebtweets. Web developer with a love for design who mostly tweets about Magento, WordPress, eCommerce, Adwords & Food. Can be a little random.