Skip to content

Allow missing APP_ENV in .env.local.php #719

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

Merged
1 commit merged into from
Jan 10, 2020
Merged

Allow missing APP_ENV in .env.local.php #719

1 commit merged into from
Jan 10, 2020

Conversation

nicolas-grekas
Copy link
Member

Q A
License MIT
Doc issue/PR -

Reported by @bendavies

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

@bendavies
Copy link
Contributor

Thanks!

ghost pushed a commit that referenced this pull request Jan 10, 2020
@ghost ghost merged commit 321ef83 into symfony:master Jan 10, 2020
@nicolas-grekas nicolas-grekas deleted the env branch January 10, 2020 16:05
@bendavies
Copy link
Contributor

bendavies commented Jan 24, 2020

hmm no, this is no good actually.

I'm not really sure what #647 was trying to solve, but it #647 + this PR break this workflow:

## DotEnv not installed
rm .env
echo '<?php return [];' > .env.local.php
APP_ENV=prod bin/console

-> 
RuntimeException: Please run "composer require symfony/dotenv"

This errors because this comparison fails:

($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? $env['APP_ENV'] ?? null) === ($env['APP_ENV'] ?? null)
// ->
prod === null = false

As above, I don't know how to fix this because I honestly can't work out what #647 was trying to achieve.
@nicolas-grekas can you advise?

Thanks.

@guilliamxavier
Copy link
Contributor

guilliamxavier commented Jan 29, 2020

(FTR: syntax error, unexpected ')' fixed in #720 and #723)

@bendavies: As I understand it, the purpose of #647 was to have e.g. APP_ENV=test bin/console always load .env.test even if .env.local.php exists [and contains 'APP_ENV' => 'prod'].

But maybe it should not have been merged, because #501 clearly said "When .env.local.php is found, other .env files are ignored",
and the docs say "After running this command [composer dump-env prod], Symfony will load the .env.local.php file to get the environment variables and will not spend time parsing the .env files".

@nicolas-grekas what do you think, should #647 be reverted?

Besides, Ben's workflow highlights a question: if you only use real environment variables and don't use any .env file nor the Dotenv component [in prod], you are still required to either create an empty .env.local.php or install symfony/dotenv, even though you actually don't need them?

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Jan 29, 2020

@guilliamxavier see #727

if you only use real environment variables and don't use any .env file nor the Dotenv component [in prod], you are still required to either create an empty .env.local.php

yes, that's desired as that's the best tradeoff for everyone.

@guilliamxavier
Copy link
Contributor

@nicolas-grekas: 719 was this PR, I guess your meant #727. Indeed, I had missed it (thanks!). But then I also found #574, to which you answered:

As you spotted, .env.local.php freezes .env files. As such and on purpose, it's only for prod-like needs. Don't use it in test nor dev.

so isn't it paradoxical that you accepted #647 (~ six months later)? The docs aren't crystal clear either, so what is the actually intended behavior?

(As for the second question, thanks for the confirmation. I also found #529.)

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Jan 29, 2020

I guess your meant #727

correct, updated

isn't it paradoxical that you accepted #647

I'm "solution oriented", no dogma, looking for a default that works for most :)

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants