Skip to content

Commit cf245d4

Browse files
committed
Updating docs for a few more .env changes
1) .env being always loaded after proposed recipe 2) A new command to dump an optimized version of those env vars 3) A new command to update your recipes
1 parent 9c1d748 commit cf245d4

9 files changed

+105
-13
lines changed

configuration.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,7 @@ You can also create a few other ``.env`` files that will be loaded:
313313
``prod`` environment but will *not* be committed to your repository.
314314

315315
If you decide to set real environment variables on production, the ``.env`` files
316-
will *not* be loaded if Symfony detects that a real ``APP_ENV`` environment variable
317-
exists and is set to ``prod``.
316+
*are* still loaded, but your real environment variables will override those values.
318317

319318
Environments & the Other Config Files
320319
-------------------------------------

configuration/dot-env-changes.rst

+47-6
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,59 @@ important changes:
3030
other environments. You can also create a ``.env.test`` file for test-environment
3131
overrides.
3232

33-
* E) If you pass the ``--env=`` flag when running ``bin/console``, this value will
34-
override your ``APP_ENV`` environment variable (if set). And so, if you pass
35-
``--env=prod``, the DotEnv component *will* try to load your ``.env*`` files.
33+
* E) `One further change to the recipe in December 2019`_ means that your ``.env``
34+
files are *always* loaded, even if you set an ``APP_ENV=prod`` environment
35+
variable. The purpose is for the ``.env`` files to define default values that
36+
you can override if you want to with real environment values.
3637

3738
There are a few other improvements, but these are the most important. To take advantage
3839
of these, you *will* need to modify a few files in your existing app.
3940

4041
Updating My Application
4142
-----------------------
4243

43-
If you created your application after November 15th 2018, you don't need to make
44-
any changes! Otherwise, here is the list of changes you'll need to make - these
45-
changes can be made to any Symfony 3.4 or higher app:
44+
First, make sure you're using ``symfony/flex`` version 1.2 or later:
45+
46+
.. code-block:: terminal
47+
48+
composer update symfony/flex
49+
50+
The easiest way to update your application is to update all of your recipes using
51+
the :ref:`sync-recipes <updating-recipes>` command. This command will update *all*
52+
your recipes, so it will probably include other changes beyond the ones needed for
53+
the new environment handling.
54+
55+
First, rename ``.env`` to ``.env.local`` and ``.env.dist`` to ``.env``:
56+
57+
.. code-block:: terminal
58+
59+
# Unix
60+
$ mv .env .env.local
61+
$ git mv .env.dist .env
62+
63+
# Windows
64+
$ mv .env .env.local
65+
$ git mv .env.dist .env
66+
67+
Now run:
68+
69+
.. code-block:: terminal
70+
71+
$ composer sync-recipes --force
72+
73+
If this asks you to overwrite uncommited changes in ``.env``, choose "no" - you
74+
should keep the values from your ``.env`` file.
75+
76+
When the command finishes, review the changes - there may be extra files or changes
77+
from other recipes that you don't want. If you made custom changes to files, you'll
78+
need to use re-add those (hint using ``git diff`` is a great way to see the changes
79+
made by the recipes).
80+
81+
Summary of the Changes
82+
~~~~~~~~~~~~~~~~~~~~~~
83+
84+
IF you want to manually update your application, here the details: these changes
85+
can be made to any Symfony 3.4 or higher app:
4686

4787
#. Create a new `config/bootstrap.php`_ file in your project. This file loads Composer's
4888
autoloader and loads all the ``.env`` files as needed (note: in an earlier recipe,
@@ -94,3 +134,4 @@ changes can be made to any Symfony 3.4 or higher app:
94134
.. _`comment on the top of .env`: https://github.com/symfony/recipes/blob/master/symfony/flex/1.0/.env
95135
.. _`create a new .env.test`: https://github.com/symfony/recipes/blob/master/symfony/phpunit-bridge/3.3/.env.test
96136
.. _`phpunit.xml.dist file`: https://github.com/symfony/recipes/blob/master/symfony/phpunit-bridge/3.3/phpunit.xml.dist
137+
.. _`One further change to the recipe in December 2019`: https://github.com/symfony/recipes/pull/501

deployment.rst

+13-2
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,18 @@ as you normally do:
172172
  using :doc:`Symfony Flex </setup/flex>`) before running this command so
173173
that the ``post-install-cmd`` scripts run in the ``prod`` environment.
174174

175-
D) Clear your Symfony Cache
175+
D) Dumping Optimized Environment Variables
176+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
177+
178+
If you're using Symfony Flex, you can get a small performance boost by running
179+
a command that reads your ``.env`` files and dumps an optimized ``.env.local.php``
180+
file that's read by your application:
181+
182+
.. code-block:: terminal
183+
184+
$ composer dump-env prod
185+
186+
E) Clear your Symfony Cache
176187
~~~~~~~~~~~~~~~~~~~~~~~~~~~
177188

178189
Make sure you clear and warm-up your Symfony cache:
@@ -181,7 +192,7 @@ Make sure you clear and warm-up your Symfony cache:
181192
182193
$ php bin/console cache:clear --env=prod --no-debug
183194
184-
E) Other Things!
195+
F) Other Things!
185196
~~~~~~~~~~~~~~~~
186197

187198
There may be lots of other things that you need to do, depending on your

quick_tour/the_architecture.rst

+2-3
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,8 @@ as *environment* variables. This means that Symfony works *perfectly* with
288288
Platform as a Service (PaaS) deployment systems as well as Docker.
289289

290290
But setting environment variables while developing can be a pain. That's why your
291-
app automatically loads a ``.env`` file, if the ``APP_ENV`` environment variable
292-
isn't set in the environment. The keys in this file then become environment variables
293-
and are read by your app:
291+
app automatically loads a ``.env`` file. The keys in this file then become environment
292+
variables and are read by your app:
294293

295294
.. code-block:: bash
296295

setup/_update_flex_recipes.rst.inc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Upgrading Flex Recipes
2+
~~~~~~~~~~~~~~~~~~~~~~
3+
4+
Some :doc:`Flex Recipes </setup/flex>` for packages you've already installed may
5+
also be out of date. You don't need to update these, but it's a great way to keep
6+
your code updated with the latest features and conventions.
7+
8+
See :ref:`updating-recipes` for details.

setup/flex.rst

+28
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,34 @@ SwiftmailerBundle and returns the "recipe" for it.
5151
Flex keeps tracks of the recipes it installed in a ``symfony.lock`` file, which
5252
must be committed to your code repository.
5353

54+
.. _updating-recipes:
55+
56+
Updating Recipes
57+
~~~~~~~~~~~~~~~~
58+
59+
Over time, recipes for packages you've already installed might be updated. Your app
60+
doesn't need these updated recipes to function, but you may want to apply the updates
61+
to take advantage of the latest features and conventions.
62+
63+
To do this, you can tell Flex to "sync" the recipes. This means it will apply the
64+
latest recipe version for each package and **overwrite** any existing files. Make
65+
sure you've committed all your files to git, and then run:
66+
67+
.. code-block:: terminal
68+
69+
$ composer sync-recipes --force
70+
71+
.. versionadded:: 1.2
72+
The ``sync-recipes --force`` command was introduced in symfony/flex 1.2.0.
73+
74+
The command will ask you before overwriting any files with uncommitted changes.
75+
76+
The tricky part about updating recipes is that you may not want or need many of
77+
the changes. Often a recipe will add a new file to help get you started, which
78+
you may not need. Feel free to delete any "extra" files you don't need, or revert
79+
any changes you don't want. Recipes are generally a great "starting" point - and
80+
your app will naturally evolve how it needs to.
81+
5482
Symfony Flex Recipes
5583
~~~~~~~~~~~~~~~~~~~~
5684

setup/upgrade_major.rst

+2
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,6 @@ When upgrading to Symfony 4, you will probably also want to upgrade to the new
160160
Symfony 4 directory structure so that you can take advantage of Symfony Flex.
161161
This takes some work, but is optional. For details, see :ref:`upgrade-to-flex`.
162162

163+
.. include:: /setup/_update_flex_recipes.rst.inc
164+
163165
.. _`Symfony-Upgrade-Fixer`: https://github.com/umpirsky/Symfony-Upgrade-Fixer

setup/upgrade_minor.rst

+2
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,7 @@ safe to update in the future.
6969

7070
These documents can also be found in the `Symfony Repository`_.
7171

72+
.. include:: /setup/_update_flex_recipes.rst.inc
73+
7274
.. _`Symfony Repository`: https://github.com/symfony/symfony
7375
.. _`UPGRADE-4.1.md`: https://github.com/symfony/symfony/blob/4.1/UPGRADE-4.1.md

setup/upgrade_patch.rst

+2
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ always safe to upgrade to the latest "minor" version.
2020
releases.
2121

2222
.. include:: /setup/_update_all_packages.rst.inc
23+
24+
.. include:: /setup/_update_flex_recipes.rst.inc

0 commit comments

Comments
 (0)