Blog

How to Enable Developer Mode in Magento2

In this article, we will see the best and safest way to switch Magento2 modes. But before that we must be aware about the modes present in the Magento2.

Magento2 platform can be used in any of these 3 offered modes. These are as below:-

  • Default Mode
  • Developer Mode
  • Product Mode
  1. 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 var/reports folder 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 Magento2 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.

When developing extensions or troubleshooting your Magento store, developer mode is the mode that you’ll want to use. Developer mode comes with various benefits such as:

  • Enhanced reporting: system logging in var/report is verbose which means an easier time troubleshooting;
  • Non-cached static files: static files are written to pub/static everytime they’re called, which means every change you make will immediately be visible on the frontend
  • Exception errors: are shown in the browser instead of being logged

All of these benefits come with a cost that is performance, so expect slower load times when you’re in this mode.

Magento 2 production mode

The mode is used as the main regime for working with Magento. If you need Magento2 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 Magento2 mode?

To know the current Magento mode, you need to run this 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.
php bin/magento deploy:mode:show

Output:-

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/*

  1. Then set the Magento 2 developer mode:
php bin/magento deploy:mode:set developer
  1. The following message should display:
Enabled developer mode

To disable developer mode in Magento2, 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.

 

 

 

You will get a message like this:

Current application mode: developer.

is using special CLI command.

Here is what you need to to:

Step 1: – Log in to your store via SSH/CLI and navigate to root of your store.

Step 2: Clean generated classes and other entities to prevent unchecked errors with command

rm -rf var/di/* var/generation/*

Step 3: Switch to developer mode using command

php bin/magento deploy:mode:set developer

Step 4: When you change to developer or production mode, we clear the contents of following directories:

=> var/cache
=> generated/metadata
=> generated/code
=> var/view_preprocessed
=> pub/static

Exceptions: .htaccess files are not removed

Step 5: Display the current mode:-

php bin/magento deploy:mode:show

Output:

 

Leave a Reply

Your email address will not be published. Required fields are marked *