|
| 1 | +Nov 2018 Changes to .env & How to Update |
| 2 | +======================================== |
| 3 | + |
| 4 | +In November 2018, several changes were made to the core Symfony *recipes* related |
| 5 | +to the ``.env`` file. These changes make working with environment variables easier |
| 6 | +and more consistent - especially when writing functional tests. |
| 7 | + |
| 8 | +If your app was started before November 2018, your app **does not require any changes |
| 9 | +to keep working**. However, if/when you are ready to take advantage of these improvements, |
| 10 | +you will need to make a few small updates. |
| 11 | + |
| 12 | +What Changed Exactly? |
| 13 | +--------------------- |
| 14 | + |
| 15 | +But first, what changed? On a high-level, not much. Here's a summary of the most |
| 16 | +important changes: |
| 17 | + |
| 18 | +* A) The ``.env.dist`` file no longer exists. Its contents should be moved to your |
| 19 | + ``.env`` file (see the next point). |
| 20 | + |
| 21 | +* B) The ``.env`` file **is** now commited to your repository. It was previously ignored |
| 22 | + via the ``.gitignore`` file (the updated recipe does not ignore this file). Because |
| 23 | + this file is committed, it should contain non-sensitive, default values. Basically, |
| 24 | + the ``.env.dist`` file was moved to ``.env``. |
| 25 | + |
| 26 | +* C) A ``.env.local`` file can now be created to *override* environment variables for |
| 27 | + your machine. This file is ignored in the new ``.gitignore``. |
| 28 | + |
| 29 | +* D) When testing, your ``.env`` file is now read, making it consistent with all |
| 30 | + other environments. You can also create a ``.env.test`` file for test-environment |
| 31 | + overrides. |
| 32 | + |
| 33 | +There are a few other improvements, but these are the most important. To take advantage |
| 34 | +of these, you *will* need to modify a few files in your existing app. |
| 35 | + |
| 36 | +Updating My Application |
| 37 | +----------------------- |
| 38 | + |
| 39 | +If you created your application after November 15th 2018, you don't need to make |
| 40 | +any changes! Otherwise, here is the list of changes you'll need to make - these |
| 41 | +changes can be made to any Symfony 3.4 or higher app: |
| 42 | + |
| 43 | +#. Create a new `src/.bootstrap.php`_ file in your project. This file loads Composer's |
| 44 | + autoloader and loads all the ``.env`` files as needed. |
| 45 | + |
| 46 | +#. Update your `public/index.php`_ (`index.php diff`_) file to load the new ``src/.bootstrap.php`` |
| 47 | + file. If you've customized this file, make sure to keep those changes (but use |
| 48 | + the rest of the changes). |
| 49 | + |
| 50 | +#. Update your `bin/console`_ (`bin/console diff`_) file to load the new ``src/.bootstrap.php`` file. |
| 51 | + |
| 52 | +#. Update ``.gitignore``: |
| 53 | + |
| 54 | + ..code-block::diff |
| 55 | +
|
| 56 | + # .gitignore |
| 57 | + # ... |
| 58 | +
|
| 59 | + ###> symfony/framework-bundle ### |
| 60 | + - /.env |
| 61 | + + /.env.local |
| 62 | + + /.env.*.local |
| 63 | +
|
| 64 | + # ... |
| 65 | +
|
| 66 | +#. Rename ``.env`` to ``.env.local`` and ``.env.dist`` to ``.env``: |
| 67 | + |
| 68 | + ..code-block::terminal |
| 69 | +
|
| 70 | + # Unix |
| 71 | + $ mv .env .env.local |
| 72 | + $ git mv .env.dist .env |
| 73 | +
|
| 74 | + # Windows |
| 75 | + $ mv .env .env.local |
| 76 | + $ git mv .env.dist .env |
| 77 | +
|
| 78 | + You can also update the `comment on the top of .env`_ to reflect the new changes. |
| 79 | + |
| 80 | +#. If you're using PHPUnit, you will also need to `create a new .env.test`_ file |
| 81 | + and update your `phpunit.xml.dist file`_ so it loads the ``src/.bootstrap.php`` |
| 82 | + file. |
| 83 | + |
| 84 | +.. _`src/.bootstrap.php`:https://github.com/symfony/recipes/blob/master/symfony/framework-bundle/3.3/src/.bootstrap.php |
| 85 | +.. _`public/index.php`:https://github.com/symfony/recipes/blob/master/symfony/framework-bundle/3.3/public/index.php |
| 86 | +.. _`index.php diff`:https://github.com/symfony/recipes/compare/8a4e5555e30d5dff64275e2788a901f31a214e79...86e2b6795c455f026e5ab0cba2aff2c7a18511f7#diff-473fca613b5bda15d87731036cb31586 |
| 87 | +.. _`bin/console`:https://github.com/symfony/recipes/blob/master/symfony/console/3.3/bin/console |
| 88 | +.. _`bin/console diff`:https://github.com/symfony/recipes/compare/8a4e5555e30d5dff64275e2788a901f31a214e79...86e2b6795c455f026e5ab0cba2aff2c7a18511f7#diff-2af50efd729ff8e61dcbd936cf2b114b |
| 89 | +.. _`comment on the top of .env`:https://github.com/symfony/recipes/blob/master/symfony/flex/1.0/.env |
| 90 | +.. _`create a new .env.test`:https://github.com/symfony/recipes/blob/master/symfony/phpunit-bridge/3.3/.env.test |
| 91 | +.. _`phpunit.xml.dist file`:https://github.com/symfony/recipes/blob/master/symfony/phpunit-bridge/3.3/phpunit.xml.dist |