@@ -28,20 +28,14 @@ override it to create your own structure:
2828 ├─ vendor/
2929 └─ .env
3030
31-
3231 .. _override-env-dir :
3332
3433Override the Environment (DotEnv) Files Directory
3534-------------------------------------------------
3635
37- Though the environment files directory is supposed to be the current project
38- root directory, you can actually set it via Composer or specifically in each
39- bootstrapper file ``index.php `` (your :ref: `front controller <from_flat_php-front-controller >`)
40- or your ``console `` file (located by default in the ``bin/ `` directory of
41- your application).
42-
43- You can change the ``runtime.dotenv_path `` option in the ``composer.json ``
44- file:
36+ By default, the :ref: `.env configuration file <config-dot-env >` is located at
37+ the root directory of the project. If you store it in a different location,
38+ define the ``runtime.dotenv_path `` option in the ``composer.json `` file:
4539
4640.. code-block :: json
4741
@@ -50,37 +44,35 @@ file:
5044 "extra" : {
5145 "..." : " ..." ,
5246 "runtime" : {
53- "dotenv_path" : " my_new_env_dir /.env"
47+ "dotenv_path" : " my/custom/path/to /.env"
5448 }
5549 }
5650 }
57-
58- .. tip ::
5951
60- Don't forget to update your Composer files (via ``composer update ``, for instance),
61- so that the ``vendor/autoload_runtime.php `` files gets regenerated to reflect
62- your environment overrides for this .
63-
64- If you want to set up different specific paths for your environment directories
65- for your console and web server calls, you'll have to use the PHP files to
66- achieve so, by altering the `` $_SERVER `` configuration .
52+ Then, update your Composer files (running ``composer update ``, for instance),
53+ so that the ``vendor/autoload_runtime.php `` files gets regenerated with the new
54+ `` .env `` path .
55+
56+ You can also set up different `` .env `` paths for your console and web server
57+ calls. Edit the `` public/index.php `` and/or `` bin/console `` files to define the
58+ new file path .
6759
68- For instance, you can do the following (starting Symfony `` 5.3 ``) ::
60+ Console script ::
6961
7062 // bin/console
7163
7264 // ...
73- $_SERVER['APP_RUNTIME_OPTIONS']['dotenv_path'] = 'my_new_console_env_dir /.env';
65+ $_SERVER['APP_RUNTIME_OPTIONS']['dotenv_path'] = 'some/custom/path/to /.env';
7466
7567 require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
7668 // ...
7769
78- And/or ::
70+ Web front-controller ::
7971
8072 // public/index.php
8173
8274 // ...
83- $_SERVER['APP_RUNTIME_OPTIONS']['dotenv_path'] = 'my_new_web_env_dir /.env';
75+ $_SERVER['APP_RUNTIME_OPTIONS']['dotenv_path'] = 'another/custom/path/to /.env';
8476
8577 require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
8678 // ...
0 commit comments