Skip to content

Added a note about container parameters and env vars #8181

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

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions components/dotenv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Load a ``.env`` file in your PHP application via ``Dotenv::load()``::

Given the following ``.env`` file content:

.. code-block:: bash
.. code-block:: shell

# .env
DB_USER=root
Expand All @@ -76,26 +76,37 @@ shell scripts:

.. code-block:: terminal

source .env
$ source .env

Add comments by prefixing them with ``#``:

.. code-block:: bash
.. code-block:: shell

# Database credentials
DB_USER=root
DB_PASS=pass # This is the secret password

Use environment variables in values by prefixing variables with ``$``:

.. code-block:: bash
.. code-block:: shell

DB_USER=root
DB_PASS=${DB_USER}pass # Include the user as a password prefix

.. note::

When using the Dotenv component within the Symfony Framework, beware that
variables can't contain container parameters because they are not resolved:

.. code-block:: shell

# '%kernel.project_dir%' is not resolved, so the value of this
# variable won't be the expected one and the application won't work
DATABASE_URL=sqlite:///%kernel.project_dir%/test.db

Embed commands via ``$()`` (not supported on Windows):

.. code-block:: bash
.. code-block:: shell

START_TIME=$(date)

Expand Down