phpsymfonydotenvsymfony6

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:


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