Introduction to Magento 2 modes To improve security and ease-of-use, Magento 2 added commands that switches Magento modes(default/ developer/ production).

1. default

If you are deploying the Magento 2 application on a single server, the default mode enables you to do so without changing any settings. However, its not optimized for production.

You need to change to anyone of the other modes, to deploy on more than one server or to optimize it for production.

In this mode, Symlinks are published for static view files to the pub/static directory. Exceptions are not displayed to the user, exceptions are written to log files. Hides custom X-Magento-* HTTP request and response headers

2. developer

This mode is intended for development purpose only.

In this mode, Symlinks are published for static view files to the pub/static directory and provides verbose logging. Enables automatic code compilation and enhanced debugging. It shows custom X-Magento-* HTTP request and response headers. The results in the slowest performance (because of the preceding).

3. production

This mode is intended for deployment on a production/live system.
In this mode, Exceptions are not displayed to the user, exceptions are written to logs only, and static view files are served from “pub/static” only. New or updated files are not written to the file system. The CSS and JS minify is possible in this mode.

Production mode also has better performance because static view files are populated in the pub/static directory and because of code compilation.

In version 2.0.6 and later, Magento 2 does not explicitly set file or directory permissions when you switch between modes. Also the developer and production modes are set in “app/etc/env.php”.

When you change to developer or production mode, Magento 2 clear the contents of following directories:

  • var/cache
  • var/di
  • var/generation
  • var/view_preprocessed
  • pub/static

Exceptions on the above:

  • .htaccess files are not removed
  • pub/static contains a file that specifies the version of static content; this file is not removed

By default, Magento 2 uses the var directories to store the cache, logs, and compiled code. You can customize this directory but in this guide, it’s assumed to be var.

How to display Magento 2 current mode

The easiest way to do that is to run below command as the Magento 2 file system owner.

Command usage: php bin/magento deploy:mode:show

A message similar to the following displays: “Current application mode: developer

Magento 2 change modes

Command usage: php bin/magento deploy:mode:set {mode} [-s| –skip-compilation]

{mode} is required; it can be either default or developer or production.

–skip-compilation is an optional parameter you can use to skip code compilation when you change to production mode.

Examples follow:-

Change to developer mode
php bin/magento deploy:mode:set developer

Following is a summary of messages that display while change to developer mode:
Change to developer mode

Change to production mode
php bin/magento deploy:mode:set production

 

Following is a summary of messages that display while change to production mode:

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.
Note :-
When you change from production to developer mode, you should clear generated classes and Object Manager entities like proxies to prevent unexpected errors. After doing so, you can change modes. Use the following steps:

If you’re changing from production mode to developer mode, delete the contents of the var/generation and var/di directories:

rm -rf <your Magento install dir>/var/di/* <your Magento install dir>/var/generation/*

Set the mode: php bin/magento deploy:mode:set developer

The following message displays: Switched to developer mode.

 

If you have any question or doubt while deploying Magento 2.x or you need any other customized extension for your store, you can contact our team of Magento development experts anytime and they will assist you with the optimized solution.

My name is Sreejith Gopinath and I am a full-stack Web Application Developer and Software Developer, currently living in TI Technologies. I have a Bachelor of Science in Computer Science from Cusat, and my primary focus and inspiration for my studies is Web Development. In my free time, I study human computer interface and the psychology of human computer interaction. I am both driven and self-motivated, and I am constantly experimenting with new technologies and techniques. I am very passionate about Web Development, and strive to better myself as a developer, and the development community as a whole.