Skip to content

Commit d6df9c8

Browse files
[DotEnv] Fix incorrect way to modify .env path
1 parent e926d7c commit d6df9c8

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

configuration.rst

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -936,22 +936,47 @@ Storing Environment Variables In Other Files
936936
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
937937

938938
By default, the environment variables are stored in the ``.env`` file located
939-
at the root of your project. However, you can store them in other file by
940-
setting the ``SYMFONY_DOTENV_PATH`` environment variable to the absolute path of
941-
that custom file.
939+
at the root of your project. However, you can store them in other files in
940+
multiple ways:
941+
942+
* By calling the :method:`Symfony\\Component\\Dotenv\\Dotenv::bootEnv`
943+
method with the path to the file as the first argument::
944+
945+
use Symfony\Component\Dotenv\Dotenv;
946+
947+
(new Dotenv())->bootEnv(dirname(__DIR__).'my/custom/path/to/.env');
948+
949+
* By adding the following directives to your ``composer.json`` file:
950+
951+
.. code-block:: json
952+
953+
{
954+
// ...
955+
"extra": {
956+
// ...
957+
"runtime": {
958+
"dotenv_path": "my/custom/path/to/.env"
959+
}
960+
}
961+
}
962+
963+
* By setting the ``APP_RUNTIME_OPTIONS`` environment variable like this
964+
in your PHP code::
965+
966+
$_SERVER['APP_RUNTIME_OPTIONS'] = ['dotenv_path' => 'my/custom/path/to/.env'];
967+
968+
.. note::
969+
970+
The first option is only possible when using the Dotenv component as standalone
971+
or when the Runtime component is not used. The second and third options are
972+
automatically enabled when using the Runtime component.
942973

943974
Symfony will then look for the environment variables in that file, but also in
944975
the local and environment-specific files (e.g. ``.*.local`` and
945976
``.*.<environment>.local``). Read
946977
:ref:`how to override environment variables <configuration-multiple-env-files>`
947978
to learn more about this.
948979

949-
.. caution::
950-
951-
The ``SYMFONY_DOTENV_PATH`` environment variable must be defined at the
952-
system level (e.g. in your web server configuration) and not in any default
953-
or custom ``.env`` file.
954-
955980
.. versionadded:: 7.1
956981

957982
The ``SYMFONY_DOTENV_PATH`` environment variable was introduced in Symfony 7.1.

0 commit comments

Comments
 (0)