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
- 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.
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/*
- Then set the Magento 2 developer mode:
- 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:–