Is this good idea to change current application mode from Env.php
-
29-09-2020 - |
Question
I have see all answer of question, How do I set Developer Mode in Magento 2
All are good.
But suddenly i got another solution myself ,by directly change MAGE_MODE
value at env.php
(app/etc/
) and here change current application mode from default to developer by MAGE_MODE' => 'default'
to MAGE_MODE' => 'developer'
.
and it been works.
But now my question is that this a good solution for change Application mode?.
Please put your views.
Solution
This is exactly what bin/magento deploy:mode:set
is doing.
See Magento\Deploy\Model\Mode::setStoreMode()
:
/**
* Store mode in env.php
*
* @param string $mode
* @return void
*/
protected function setStoreMode($mode)
{
$data = [
ConfigFilePool::APP_ENV => [
State::PARAM_MODE => $mode
]
];
$this->writer->saveConfig($data);
}
Generally, env.php
is a generated file that is not meant to be modified manually. Changing values there will work though, as they are read from the file before any other changes are made automatically.
In conclusion, you can do it but there should be no reason to if you have access to the bin/magento
CLI tool.
OTHER TIPS
After some time experimenting with modes, especially with deployment workflows, I'd like to highlight a slight difference btw setting mode via bin/magento
and changing the app/etc/env.php
file.
The bin/magento deploy:mode:set production
automatically triggers other actions, such as setting maintenance mode, deploying static contents, compiling DI etc.
In some circumstances (like during a deployment process) you would like to have control on these actions, thus changing the app/etc/env.php
manually could be a viable option.
Hope it helps.