Skip to content

[DotEnv] .env.local should override existing defined variables #29647

Closed
@ruudk

Description

@ruudk

Symfony version(s) affected: 4.2.1

Description
I'm following the new approach to .env files as described here.

My .env file contains:

APP_ENV=dev
APP_DEBUG=1
STRIPE_KEY=

And my .env.local file contains:

STRIPE_KEY=MY_KEY

When I create a service that injects this %env(STRIPE_KEY)% it's always empty.

When I remove the STRIPE_KEY= placeholder from my .env file it suddenly works.

The issue is that it first loads the .env file, sets the STRIPE_KEY to blank, then loads the .env.local file and just skips the STRIPE_KEY=MY_KEY because it's already defined.

Possible Solution
Always let .env.local override the environment variables defined in .env

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions