helhum/dotenv-connector

.env.<environment> overrides .env.local with SymfonyLoadEnv adapter

Closed this issue · 3 comments

I am using the following setup:

.env with CLOUDFLARE_API_TOKEN=
.env.production with CLOUDFLARE_API_TOKEN=
.env.local with CLOUDFLARE_API_TOKEN=ABC

I was wondering why the CLOUDFLARE_API_TOKEN is always empty when accessing the env vars in TYPO3. Then I removed the CLOUDFLARE_API_TOKEN from the .env.production file and voila the value is ABC.

Is this a bug in the SymfonyLoadEnv adapter since on symfony the .env.local file does override everything defined in the .env or .env.<environment> files?

on symfony the .env.local file does override everything defined in the .env or .env.<environment> files?

I don't think this is true.
Afaik .env.<environment> overrides .env.local but .env.<environment>.local overrides .env.<environment>.

See: https://symfony.com/doc/current/configuration.html#overriding-environment-values-via-env-local

I have no idea honestly. Please refer to the Symfony documentation, if you are using this way to populate the env vars from files.

@jdreesen

Are you sure?

.env.local: overrides the default values for all environments but only on the machine which contains the file. This file should not be committed to the repository and it's ignored in the test environment (because tests should produce the same results for everyone);

and

.env.<environment>.local (e.g. .env.test.local): defines machine-specific env var overrides only for one environment. It's similar to .env.local, but the overrides only apply to one environment.

I'm not quite sure but for me the .env.local overrides the values for every environment. I will test that out again on a barebone symfony project.

--

Update:

Tested it out and you are right. Thank you very much. I was wrong.

To be honest the docs are not that clear about it I think.

In production, the .env files are also parsed and loaded on each request. So the easiest way to define env vars is by deploying a .env.local file to your production server(s) with your production values.

did lead me in the wrong direction.