How to Set Magento 2 Developer Mode
The Magento 2 offers three different modes for users which are default mode, developer mode, and production mode.
Depend on particular situations, store admin can apply different modes for their Magento store.
Magento2 developer mode :
The Developer mode of Magento is used when whenever you are customizing or extending the Magento 2’s default functionalities.
Developer mode will be used for the following reasons :
- Publish a symlink of each required file to the pub/static directory.
- Uncaught exceptions are seen in the browser.
- The system logging in var/report is verbal. Put the exception into the error handler.
- Generate the exception if an event subscriber cannot be enforced.
Magento2 check developer mode :
- To check current magento mode, you have to run below command :
- php bin/magento deploy:mode:show
- After running Command below message will be displayed :
- Current application mode: {mode}.
Here, mode can be default mode, developer mode, and production mode.
Magento 2 developer mode enable :
There are two ways available to enable developer mode in magento 2 1)Manually Using env.php 2) Using Command line
1)Manually Using env.php :
To Enable Developer Mode manually using env.php file, you have to follow below steps :
- Open file env.php located at app /etc / with any text editor. Then search for below line of code :
'x-frame-options' => 'SAMEORIGIN', 'MAGE_MODE' => 'default', 'session' => [ 'save' => 'files' ], |
Now replace from 'MAGE_MODE' => 'default', to 'MAGE_MODE' => 'developer', as below :
'x-frame-options' => 'SAMEORIGIN', 'MAGE_MODE' => 'developer', 'session' => [ 'save' => 'files' ], |
Now, Save the env.php file after changes and refresh the website to see the changes.
If you don’t find developer mode applied then, flush the cache, and then you can see the changes.
2) Using Command Line :
To Enable Developer Mode using command line, you have to follow below steps :
- The generated/metadata and generated/code directories should be deleted. To remove these directories, run the below command :
- rm -rf /generated/metadata/* /generated/code/*
- Now to change mode you have to run below command :
- php bin/magento deploy:mode:set developer
- After running Command below message will be displayed :
- Enabled developer mode.
Magento 2 developer mode disable :
There is two ways availilable to disable devloper mode in magento 2 1)Manually Using env.php 2) Using Command line
1)Manually Using env.php :
To Disable Developer Mode manually using env.php file, you have to follow below steps :
- Open file env.php located at app /etc / with any text editor. Then search for below line of code :
'x-frame-options' => 'SAMEORIGIN', 'MAGE_MODE' => 'developer', 'session' => [ 'save' => 'files' ], |
Now replace from 'MAGE_MODE' => 'developer', to 'MAGE_MODE' => 'production', OR 'MAGE_MODE' => 'production', But Here I have shown example of production mode as below :
'x-frame-options' => 'SAMEORIGIN', 'MAGE_MODE' => 'production', 'session' => [ 'save' => 'files' ], |
Now, Save the env.php file after changes and refresh website for see the changes.
If you don’t find production mode applied then, flush the cache and then you can see the changes.
2):Using Command line
To Disable Devloper Mode using command line you have to change mode from devloper to default or production mode.
- Now to change mode you have to run below command :
- php bin/magento deploy:mode:set production
- php bin/magento deploy:mode:set default
- After running Command below message will be displayed :
- Enabled production mode
- Enabled default mode
Magento 2 difference between developer and production mode and default mode :
- Default Mode :
- This mode is used when no other mode is specified.
- This mode hides exceptions from the user and writes them to log files So, debugging is difficult.
- Static view files are first materialized and then cached So, this mode is not ideal for the production environment.
- Symlinks to the static view files are published to the pub/static.
- Developer Mode :
- You should use this mode whenever you are customizing or extending the Magento 2’s default functionalities.
- Uncaught exceptions and errors are displayed in the browser So, debugging is easy.
- Static view files are written to the Magento pub/static directory every time they’re called and are not cached.
- System logging in var/report, highly detailed in this mode.
- Production Mode :
- Deployment phase on the production system; highest performance.
- This mode hides exceptions from the user and writes them to log files So, debugging is difficult.
- This mode disables static file materialization.
- Production mode uses full page caching with a fully built pub folder to pull from, that results in the smooth and efficient functioning of the store So, If you want to offer the best customer experience, you must switch your store to this mode.
- In terms of security, the production mode is the most secure because there is no symlink created for the pub/static folder.
Magento 2 developer mode not working :
In devloper mode, files will be loading from the pub/static folder.key difference is that in the pub/static/.htaccess file routes the request to the pub/static.php file, which generates symlinks to populate the pub/static folders with your files, on demand.
So, to fix developer mode not working issue we have to follow below step :
- If you are running Apache, don't delete pub/static/.htaccess, and also check that Apache is configured to use .htaccess files.
If you are running Nginx, check the site configuration is correct.
You can find examples of how to set up the /static/rewrite at the nginx.conf.sample file.
Magento 2 developer mode CSS not loading :
This could be a permission issue for your var and pub/static folders.
So please give full permission to your var and pub/static folders from root using command line.
After given root permission to your system path run below command,
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush
After running above commands, just remove browser cache and check again.
Magento 2 developer mode static-content :
In Magento 2 we have to run deploy command if we have made changes in HTML, CSS and JavaScript.
But when we are in developer mode and enabled symlinks in system, then we don’t need to run this command.
Because In developer mode symlinks are generated to populate the pub/static folders with your files, on demand means whenever magento require particular file.
But when symlinks are disabled then we need to run deploy command, but we need to delete particular changed files from pub/static folder.
So, to run deploy command, we have to run commands as below :
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush
Conclusion:
We hope the above blog helps you to clearly understand How to Set Magento 2 Developer Mode.
From this blog you can easily understand about Enable / Disable Developer mode, switching modes in between default, developer and production, and key difference between default, developer and production.