Skip to content
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

Checking APP_* in $_SERVER var isn't suffisant #331

Closed
matthieugauthier opened this issue Jan 4, 2018 · 5 comments
Closed

Checking APP_* in $_SERVER var isn't suffisant #331

matthieugauthier opened this issue Jan 4, 2018 · 5 comments

Comments

@matthieugauthier
Copy link

In file recipes/symfony/framework-bundle/3.3/public/index.php ,

checking APP_* in $SERVER var isn't suffisant, in certain docker context, APP* vars are set in entrypoint and must be checked by $_ENV var.

It would be usefull to check both vars in index.php .

@Pierstoval
Copy link
Contributor

Pierstoval commented Jan 5, 2018

Do you have a reproducible case where APP_ENV is set in $_ENV and not in $_SERVER?

@matthieugauthier
Copy link
Author

@Pierstoval
Copy link
Contributor

Pierstoval commented Jan 5, 2018

In your case, it's because you override the env var in your entrypoint.sh. This is not usual, but this is an edge case that has to be fixed 👍

I proposed symfony/symfony#25693 to see if we can fix this in the framework instead.

For now, as a fallback you can use a more reliable method like this:

if (!isset($_SERVER['APP_ENV'], $_ENV['APP_ENV']) && false === getenv('APP_ENV')) {
    if (!class_exists(Dotenv::class)) {
        throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
    }
    (new Dotenv())->load(__DIR__.'/../.env');
}

$env = $_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? getenv('APP_ENV');

@zim32
Copy link

zim32 commented Apr 3, 2018

I can't understand. I have APP_ENV set to dev. And my .dot file is not loaded in this scenario.
Bu it must be loaded in dev env.

@jrjohnson
Copy link

I believe this is resolved in #464

@Tobion Tobion closed this as completed Oct 3, 2018
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

No branches or pull requests

5 participants