[Configuration][Doctrine] Document .env quoting and separate connection parameters for special characters

This commit is contained in:
lacatoire
2026-02-05 13:00:20 +01:00
parent 5c1395ebc7
commit 1fefe21d9d
2 changed files with 42 additions and 0 deletions

View File

@@ -824,6 +824,21 @@ Define a default value in case the environment variable is not set:
DB_USER=
DB_PASS=${DB_USER:-root}pass # results in DB_PASS=rootpass
Wrap values with single quotes to use them as literal strings where ``$``,
``#`` and other special characters have no special meaning:
.. code-block:: bash
DB_PASS='p@ss#w$rd'
With double quotes, variables are still interpolated but ``#`` and other
characters are treated as literal:
.. code-block:: bash
DB_PASS="p@ss#word"
DB_NAME="my_${DB_USER}_database"
Embed commands via ``$()`` (not supported on Windows):
.. code-block:: bash

View File

@@ -68,6 +68,33 @@ The database connection information is stored as an environment variable called
In this case you need to remove the ``resolve:`` prefix in ``config/packages/doctrine.yaml``
to avoid errors: ``url: '%env(DATABASE_URL)%'``
.. tip::
To avoid URL-encoding issues with special characters in credentials, you can
use separate connection parameters instead of the URL format. Define each
value as its own environment variable and wrap it in single quotes in the
``.env`` file to prevent characters like ``$`` and ``#`` from being
interpreted:
.. code-block:: text
# .env
DATABASE_PASSWORD='p@ss$wo#rd'
Then configure Doctrine to use individual parameters:
.. code-block:: yaml
# config/packages/doctrine.yaml
doctrine:
dbal:
user: '%env(DATABASE_USER)%'
password: '%env(DATABASE_PASSWORD)%'
host: '%env(DATABASE_HOST)%'
port: '%env(DATABASE_PORT)%'
dbname: '%env(DATABASE_NAME)%'
driver: pdo_mysql
Now that your connection parameters are setup, Doctrine can create the ``db_name``
database for you: