Magento 2 modes: set the developer/production mode

What are Magento 2 modes?

Magento 2 platform can be used in any of these 3 offered modes:

Magento 2 default mode

The mode shows how the platform operates without any custom settings. Running the mode you can set up the Magento app on a single server without any changes. Nevertheless, the default mode lacks essential characteristics used for production. Therefore, if you need to set up the platform on several servers or use it for production, you need to choose among the modes listed below.

Detailed consideration:

  • Errors gathering and storage are managed in the file reports at server, thus excluding their visibility to customers;
  • A symlink of each required file is published to the pub/static directory;
  • Static files can be better created and generated using the static file creation tool.

Magento 2 developer mode

The mode is used in case you need to customize Magento 2 or install extensions.

Detailed consideration:

  • A symlink of each required file is published to the pub/static directory;
  • You will see uncaught exceptions in the browser;
  • System logging in var/report is verbal. The exception is put into the error handler;
  • The exception is generated if an event subscriber cannot be enforced.

Magento 2 production mode

The mode is used as the main regime for working with Magento. If you need Magento 2 to be set up on a production server, this mode should be applied.

Detailed consideration:

  • URLs for static view files  are created at a go, as long as the files are not materialized;
  • Errors are put into the file system staying invisible for customers.

How to check the current Magento 2 mode?

Use the php bin/magento deploy:mode:show command as the Magento file system owner:

  • If running a shared hosting, apply the user given to you by the provider.
  • If running a private server, use the local user account.

You will get a message like this:

Current application mode: developer.

How to change my Magento 2 default mode?

Use the php bin/magento deploy:mode:set {mode} [-s|--skip-compilation] command to switch to a mode you need.

*In this command {mode} stands for either developer or production mode;

--skip-compilation is an optional specification used only during modes change for code compilation avoidance.

E.g.#1: change to Magento 2 developer mode

If you want to change or enable the production mode to developer, all the generated classes and Object Manager entities should be cleared for preventing possible errors, for instance, entities like proxies should be cleared before a Magento 2 mode change.

1.The var/generation, var/directories content should be deleted:

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

2. Then set the Magento 2 developer mode:

php bin/magento deploy:mode:set developer

3. Receive the next message:

Switched to developer mode.

To disable developer mode in Magento 2, switch the mode to production.

E.g.#2: Enable Magento 2 production mode

If changing the {mode} parameter to production, you’ll get the next messages:

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 <span term-uuid="45f1f76d-91cd-4789-a8b5-1e3f321a6280" class="glossary-term" data-toggle="popover">SASS</span> files <span term-uuid="6c5cb4e9-9197-46f2-ba79-6147d9bfe66d" class="glossary-term" data-toggle="popover">CSS</span> 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.

The developer and production modes are the most usable among Magento admins. All the modes are interchangeable. The only exception is the default mode, which can’t be applied after switching to the developer one. 

According to the statistics, you may find helpfull the following question about less compilation modes

How to set up developer mode in Magento 2 admin panel?

There is no direct setting in the admin panel, but you can do it using certain commands.

You need to use the php bin/magento deploy:mode:set {mode} [-s|--skip-compilation] command to switch to a mode.

*In this command {mode} stands for either developer or production mode;

* --skip-compilation is an optional specification used only during modes change for code compilation avoidance.

If you want to change or enable the production mode to developer, all the generated classes and Object Manager entities should be cleared for preventing possible errors, for instance, entities like proxies should be cleared before a mode change.

Step 1. You should delete the var/generation and var/directories content:

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

Step 2. The next step is to set the required mode:

php bin/magento deploy:mode:set developer

After these steps you will get a message:

Switched to developer mode.

How can we help you?

Didn’t you find the answer to your question? We are always happy to help you out.