Skip to content

Commit 024fa58

Browse files
committed
feature #13084 [Deployment] Update deployment docs with new .env files 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
2 parents 8548427 + b905b57 commit 024fa58

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

deployment.rst

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,21 +126,29 @@ While developing locally, you'll usually store these in ``.env`` and ``.env.loca
126126

127127
1. Create "real" environment variables. How you set environment variables, depends
128128
on your setup: they can be set at the command line, in your Nginx configuration,
129-
or via other methods provided by your hosting service.
129+
or via other methods provided by your hosting service;
130130

131-
2. Or, create a ``.env.local`` file like your local development (see note below)
131+
2. Or, create a ``.env.local`` file like your local development.
132132

133133
There is no significant advantage to either of the two options: use whatever is
134134
most natural in your hosting environment.
135135

136-
.. note::
136+
.. tip::
137+
138+
You might not want your application to process the ``.env.*`` files on
139+
every request. You can generate an optimized ``.env.local.php`` which
140+
overrides all other configuration files:
141+
142+
.. code-block:: terminal
143+
144+
$ composer dump-env prod
137145
138-
If you use the ``.env.*`` files on production, you may need to move your
139-
``symfony/dotenv`` dependency from ``require-dev`` to ``require`` in ``composer.json``:
146+
The generated file will contain all the configuration stored in ``.env``. If you
147+
want to rely only on environment variables, generate one without any values using:
140148

141149
.. code-block:: terminal
142150
143-
$ composer require symfony/dotenv
151+
$ composer dump-env prod --empty
144152
145153
C) Install/Update your Vendors
146154
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)