Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Symfony ignores / does not override values by .env.local file

Using latest Symfony 6.1 and documentation says .env.local overrides values which are set in .env

This is not working for me, i.e. when the value is set in the .env, it is not overwritten by the value from the .env.local. When it is not set in .env, value from .env.local is taken into account.

Ref:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I had the same problem lately.

I found out, that since Symfony 5.4 there was added runtime option dotenv_overload what is set to false by default.

That is set over APP_RUNTIME_OPTIONS, what you can update by the documentation this way:

#public/index.php  
#bin/console  
  
$_SERVER['APP_RUNTIME_OPTIONS'] = [
    'dotenv_overload' => true,
];

Note: it is needed to update in 2 files bin/console for cli and public/index.php to enable .env.local overwritting.
Note2: the option dotenv_overload is missing for some reason in documentation though

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading