Skip to content

Commit a17ea5a

Browse files
committed
minor #11220 Updated the main article about env vars (javiereguiluz)
This PR was squashed before being merged into the 4.2 branch (closes #11220). Discussion ---------- Updated the main article about env vars Some parts of this article felt legacy, even its title. Let's modernize it a bit. Commits ------- e433e53 Updated the main article about env vars
2 parents c573c1b + e433e53 commit a17ea5a

File tree

8 files changed

+32
-33
lines changed

8 files changed

+32
-33
lines changed

_build/redirection_map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,3 +412,4 @@
412412
/session/avoid_session_start /session
413413
/session/sessions_directory /session
414414
/frontend/encore/legacy-apps /frontend/encore/legacy-applications
415+
/configuration/external_parameters /configuration/environment_variables

best_practices/configuration.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ application behavior.
1616
.. best-practice::
1717

1818
Define the infrastructure-related configuration options as
19-
:doc:`environment variables </configuration/external_parameters>`. During
20-
development, use the ``.env`` and ``.env.local`` files at the root of your project
21-
to set these.
19+
:doc:`environment variables </configuration/environment_variables>`. During
20+
development, use the ``.env`` and ``.env.local`` files at the root of your
21+
project to set these.
2222

2323
By default, Symfony adds these types of options to the ``.env`` file when
2424
installing new dependencies in the app:

configuration.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ percent signs - e.g. ``%locale%``.
208208
.. seealso::
209209

210210
You can also set parameters dynamically, like from environment variables.
211-
See :doc:`/configuration/external_parameters`.
211+
See :doc:`/configuration/environment_variables`.
212212

213213
For more information about parameters - including how to reference them from inside
214214
a controller - see :ref:`service-container-parameters`.

configuration/external_parameters.rst renamed to configuration/environment_variables.rst

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
11
.. index::
2-
single: Environments; External parameters
2+
single: Environment Variables; env vars
33

4-
How to Set external Parameters in the Service Container
5-
=======================================================
4+
How to Configure Symfony With Environment Variables
5+
===================================================
66

77
In :doc:`/configuration`, you learned how to manage your application
8-
configuration. At times, it may benefit your application to store certain
9-
credentials outside of your project code. Database configuration is one such
10-
example. The flexibility of the Symfony service container allows you to do this.
8+
configuration. In this article you'll learn how to use environment variables (or
9+
"env vars" for short) to configure some of those options, which is a common
10+
practice to configure sensitive options such as credentials and passwords.
1111

1212
.. _config-env-vars:
1313

14-
Environment Variables
15-
---------------------
14+
Referencing Env Vars in Configuration Files
15+
-------------------------------------------
1616

17-
You can reference environment variables by using special parameters named after
18-
the variables you want to use enclosed between ``env()``. Their actual values
19-
will be resolved at runtime (once per request), so that dumped containers can be
20-
reconfigured dynamically even after being compiled.
21-
22-
For example, when installing the ``doctrine`` recipe, database configuration is
23-
put in a ``DATABASE_URL`` environment variable:
17+
First, define the value of the env var, using your shell environment or the
18+
``.env`` file at the project root directory. For example, consider the
19+
``DATABASE_URL`` env var defined when installing the ``doctrine`` recipe (by
20+
convention the env var names are always uppercase):
2421

2522
.. code-block:: bash
2623
2724
# .env
2825
DATABASE_URL="mysql://db_user:db_password@127.0.0.1:3306/db_name"
2926
30-
This variable is referenced in the service container configuration using
31-
``%env(DATABASE_URL)%``:
27+
Then, you can reference those env vars in any configuration option enclosing
28+
their names with ``env()``. Their actual values will be resolved at runtime
29+
(once per request), so that dumped containers can be reconfigured dynamically
30+
even after being compiled:
3231

3332
.. configuration-block::
3433

@@ -69,8 +68,8 @@ This variable is referenced in the service container configuration using
6968
]
7069
]);
7170
72-
You can also give the ``env()`` parameters a default value: the default value
73-
will be used whenever the corresponding environment variable is *not* found:
71+
You can also give the ``env()`` parameters a default value, which will be used
72+
whenever the corresponding environment variable is *not* found:
7473

7574
.. configuration-block::
7675

@@ -101,7 +100,7 @@ will be used whenever the corresponding environment variable is *not* found:
101100
.. _configuration-env-var-in-prod:
102101

103102
Configuring Environment Variables in Production
104-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
103+
-----------------------------------------------
105104

106105
During development, you'll use the ``.env`` file to configure your environment
107106
variables. On your production server, it is recommended to configure these at

configuration/environments.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,4 +361,4 @@ includes the following:
361361
Going further
362362
-------------
363363

364-
Read the article on :doc:`/configuration/external_parameters`.
364+
Read the article on :doc:`/configuration/environment_variables`.

doctrine/pdo_session_storage.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ To use it, first register a new handler service:
6868
6969
.. tip::
7070

71-
Configure the database credentials as
72-
:doc:`parameters defined with environment variables </configuration/external_parameters>`
71+
Configure the database credentials
72+
:doc:`using environment variables in the config file </configuration/environment_variables>`
7373
to make your application more secure.
7474

7575
Next, tell Symfony to use your service as the session handler:

reference/configuration/swiftmailer.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,10 @@ the information will be available in the profiler.
253253

254254
.. tip::
255255

256-
The following options can be set via environment variables using the
257-
``%env()%`` syntax: ``url``, ``transport``, ``username``, ``password``,
258-
``host``, ``port``, ``timeout``, ``source_ip``, ``local_domain``,
259-
``encryption``, ``auth_mode``.
260-
For details, see the :doc:`/configuration/external_parameters` article.
256+
The following options can be set via environment variables: ``url``,
257+
``transport``, ``username``, ``password``, ``host``, ``port``, ``timeout``,
258+
``source_ip``, ``local_domain``, ``encryption``, ``auth_mode``. For details,
259+
see: :doc:`/configuration/environment_variables`.
261260

262261
Using Multiple Mailers
263262
----------------------

service_container/parameters.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ for all parameters that are arrays.
245245
Environment Variables and Dynamic Values
246246
----------------------------------------
247247

248-
See :doc:`/configuration/external_parameters`.
248+
See :doc:`/configuration/environment_variables`.
249249

250250
.. _component-di-parameters-constants:
251251

0 commit comments

Comments
 (0)