@@ -936,22 +936,45 @@ Storing Environment Variables In Other Files
936
936
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
937
937
938
938
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
+ If you use the :doc: `Runtime component </components/runtime >`, the dotenv
943
+ path is part of the options you can set in your ``composer.json `` file:
944
+
945
+ .. code-block :: json
946
+
947
+ {
948
+ // ...
949
+ "extra" : {
950
+ // ...
951
+ "runtime" : {
952
+ "dotenv_path" : " my/custom/path/to/.env"
953
+ }
954
+ }
955
+ }
956
+
957
+ You can also set the ``SYMFONY_DOTENV_PATH `` environment variable at system
958
+ level (e.g. in your web server configuration or in your Dockerfile):
959
+
960
+ .. code-block :: bash
961
+
962
+ # .env (or .env.local)
963
+ SYMFONY_DOTENV_PATH=my/custom/path/to/.env
964
+
965
+ Finally, you can directly invoke the ``Dotenv `` class in your
966
+ ``bootstrap.php `` file or any other file of your application::
967
+
968
+ use Symfony\Component\Dotenv\Dotenv;
969
+
970
+ (new Dotenv())->bootEnv(dirname(__DIR__).'my/custom/path/to/.env');
942
971
943
972
Symfony will then look for the environment variables in that file, but also in
944
973
the local and environment-specific files (e.g. ``.*.local `` and
945
974
``.*.<environment>.local ``). Read
946
975
:ref: `how to override environment variables <configuration-multiple-env-files >`
947
976
to learn more about this.
948
977
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
-
955
978
.. versionadded :: 7.1
956
979
957
980
The ``SYMFONY_DOTENV_PATH `` environment variable was introduced in Symfony 7.1.
0 commit comments