@@ -936,22 +936,48 @@ 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
+ * 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 :doc: `Runtime component </components/runtime >` is not used. The
972
+ second and third options are automatically enabled when using the
973
+ Runtime component.
942
974
943
975
Symfony will then look for the environment variables in that file, but also in
944
976
the local and environment-specific files (e.g. ``.*.local `` and
945
977
``.*.<environment>.local ``). Read
946
978
:ref: `how to override environment variables <configuration-multiple-env-files >`
947
979
to learn more about this.
948
980
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
981
.. versionadded :: 7.1
956
982
957
983
The ``SYMFONY_DOTENV_PATH `` environment variable was introduced in Symfony 7.1.
0 commit comments