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

Skip to content

Move dotenv to "require" #122

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
merged 1 commit into from
Nov 30, 2018
Merged

Move dotenv to "require" #122

merged 1 commit into from
Nov 30, 2018

Conversation

nicolas-grekas
Copy link
Member

This doesn't hurt anything and should ease using .env files without issues.

Copy link
Contributor

@Pierstoval Pierstoval left a comment

Choose a reason for hiding this comment

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

I remember how many people said that it's a bad idea to add this component to require. But I think it's ok 👍

@Tobion
Copy link

Tobion commented Nov 15, 2018

👎 symfony/recipes#491 (comment)

@nicolas-grekas
Copy link
Member Author

Merging this would fix symfony/recipes#497
I think we should merge.

@chalasr
Copy link
Member

chalasr commented Nov 22, 2018

Not fond of promoting dotenv for production personally, I'd prefer to not do this change if we can.

@nicolas-grekas
Copy link
Member Author

It's just adding the classes in vendor/ so they could be used.
Promoting or not belongs to the doc, not to these technical things.

@fabpot
Copy link
Member

fabpot commented Nov 22, 2018

From a user perspective (DX I would say), I'm ok with adding dotenv in require.

Copy link
Member

@weaverryan weaverryan left a comment

Choose a reason for hiding this comment

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

This improves DX, and the cost is extremely low if you don't need it. We will still recommend real env vars, but if you're not in an environment where those are feasible/reasonable, I'd like things to be set up nicely.

@Tobion
Copy link

Tobion commented Nov 26, 2018

You will not get an error if you forgot to define env vars. How can this be good DX? This is a security risk and bug festival.

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Nov 26, 2018

Yes you will, but at the container level. The .env files should provide default values, that's all. If you forgot to set one of them, the app will react accordingly. Having dotenv in dev for the reason you mention is a very loose band-aid I wouldn't recommend anyone to rely on.

@Tobion
Copy link

Tobion commented Nov 26, 2018

So why would env vars me missing if it reads the .env file which sets the default values? What's your solution that is more reliable and works 100% of the cases?

@nicolas-grekas
Copy link
Member Author

To verify that all env vars are defined, you could have a script that loads .env files and then ensures the SYMFONY_DOTENV_VARS is empty. This script would make your deployment fail if not.

@keradus
Copy link
Member

keradus commented Nov 26, 2018

To be honest, that extra script sounds like a workaround

@nicolas-grekas nicolas-grekas merged commit 5cd4dd8 into 3.4 Nov 30, 2018
nicolas-grekas added a commit that referenced this pull request Nov 30, 2018
This PR was merged into the 3.4 branch.

Discussion
----------

Move dotenv to "require"

This doesn't hurt anything and should ease using .env files without issues.

Commits
-------

5cd4dd8 Move dotenv to "require"
@nicolas-grekas nicolas-grekas deleted the dotenv-nodev branch November 30, 2018 09:48
wouterj added a commit to symfony/symfony-docs that referenced this pull request Oct 21, 2020
…s logic (cristi-contiu)

This PR was submitted for the 4.1 branch but it was merged into the 4.4 branch instead.

Discussion
----------

[Deployment] Update deployment docs with new .env files logic

The [changes from last year regarding how the ``.env`` files are loaded](https://symfony.com/doc/current/configuration/dot-env-changes.html) can affect production deployments. Vendors like [Heroku](https://devcenter.heroku.com/articles/deploying-symfony4#environment-variables) give recommendations based on documentation that no longer applies: "It is recommended that you do not use the symfony/dotenv package in production".

The ``symfony/dotenv`` has been moved from ``require-dev`` to ``require``, so the note I removed in this PR no longer applies: symfony/skeleton#122 , symfony/website-skeleton#132 and symfony/demo@7ead1e4 . Loading ``.env`` files in production will work without any changes in composer.json.

Putting ``symfony/dotenv`` in ``require-dev`` (or not moving it to ``require`` during an upgrade from older versions of Symfony & recipes) can potentially break your app: if the DotEnv class is missing, the [`config/bootstrap.php` file inside the FrameworkBundle's recipe will throw a RuntimeException](https://github.com/symfony/recipes/blob/master/symfony/framework-bundle/3.3/config/bootstrap.php#L14) . Also see symfony/recipes#501

The note now contains the right way to handle these files in production, by using ``$ composer dump-env prod`` in case you do not want the ``.env`` files to be processed on every request, also suggesting the ``--empty`` flag if you want to rely exclusively on "real" environment variables .

Commits
-------

b905b57 Update deployment docs with new .env loading
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.

7 participants