Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ruudk opened this issue Dec 18, 2018 · 7 comments
Closed

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

ruudk opened this issue Dec 18, 2018 · 7 comments

Comments

@ruudk
Copy link
Contributor

ruudk commented Dec 18, 2018

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

@ro0NL
Copy link
Contributor

ro0NL commented Dec 18, 2018

Could it be e.g. docker detects up .env and creates real vars as such? Renaming it to .env.dist worked for me (#29170 + #29171)

@ruudk
Copy link
Contributor Author

ruudk commented Dec 18, 2018

@ro0NL Thanks, but I'm not running this inside Docker.

@ro0NL
Copy link
Contributor

ro0NL commented Dec 18, 2018

So no "real env vars" are involved? I was unable to reproduce it actually, for me it seems to just work (i both tested .env OR .env.dist, with AND without .env.local. bin/console about confirms the right values.

@xabbuh
Copy link
Member

xabbuh commented Dec 18, 2018

@ruudk Can you create an example application that allows to reproduce?

@ruudk
Copy link
Contributor Author

ruudk commented Dec 18, 2018

I'm sorry but I just checked out a new project, and it just works like you expect it to work. Then I retried on my own project and it worked. I feel really silly now :( Thanks for the fast help, not sure what was going wrong.

@ruudk ruudk closed this as completed Dec 18, 2018
@ruudk
Copy link
Contributor Author

ruudk commented Dec 18, 2018

Ok, it appears that the issue is related to Symfony Cloud CLI tool not reading the .env files.

How to reproduce?

$ composer create-project symfony/website-skeleton my-project
$ cd my-project/
$ symfony php bin/console about
 -------------------- ---------------------------------
  Symfony
 -------------------- ---------------------------------
  Version              4.2.1
  End of maintenance   07/2019
  End of life          01/2020
 -------------------- ---------------------------------
  Kernel
 -------------------- ---------------------------------
  Type                 App\Kernel
  Environment          dev
  Debug                true
  Charset              UTF-8
  Cache directory      ./var/cache/dev (3.2 MiB)
  Log directory        ./var/log (0 B)
 -------------------- ---------------------------------
  PHP
 -------------------- ---------------------------------
  Version              7.3.0
  Architecture         64 bits
  Intl locale          en_US_POSIX
  Timezone             UTC (2018-12-18T16:57:54+00:00)
  OPcache              true
  APCu                 false
  Xdebug               false
 -------------------- ---------------------------------


$ bin/console about
-------------------- ----------------------------------------------------
  Symfony
 -------------------- ----------------------------------------------------
  Version              4.2.1
  End of maintenance   07/2019
  End of life          01/2020
 -------------------- ----------------------------------------------------
  Kernel
 -------------------- ----------------------------------------------------
  Type                 App\Kernel
  Environment          dev
  Debug                true
  Charset              UTF-8
  Cache directory      ./var/cache/dev (3.2 MiB)
  Log directory        ./var/log (0 B)
 -------------------- ----------------------------------------------------
  PHP
 -------------------- ----------------------------------------------------
  Version              7.3.0
  Architecture         64 bits
  Intl locale          en_US_POSIX
  Timezone             UTC (2018-12-18T16:59:26+00:00)
  OPcache              true
  APCu                 false
  Xdebug               false
 -------------------- ----------------------------------------------------
  Environment (.env)
 -------------------- ----------------------------------------------------
  APP_ENV              dev
  APP_SECRET           085d34ba9a84bd266a1c993be63a2431
  DATABASE_URL         mysql://db_user:[email protected]:3306/db_name
  MAILER_URL           BLAAT
  STRIPE_KEY
 -------------------- ----------------------------------------------------

I guess I have to report this at https://github.com/symfonycorp/symfony-cli-issues?

@ruudk
Copy link
Contributor Author

ruudk commented Dec 18, 2018

Found out that the issue is that Symfony CLI passes APP_ENV=dev to the commands it runs via symfony php causing the .env.local to be ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants