File tree Expand file tree Collapse file tree 1 file changed +60
-1
lines changed Expand file tree Collapse file tree 1 file changed +60
-1
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,66 @@ override it to create your own structure:
2525 │ ├─ cache/
2626 │ ├─ log/
2727 │ └─ ...
28- └─ vendor/
28+ ├─ vendor/
29+ └─ .env
30+
31+
32+ .. _override-env-dir :
33+
34+ Override the Environment (DotEnv) Files Directory
35+ -------------------------------------------------
36+
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:
45+
46+ .. code-block :: json
47+
48+ {
49+ "..." : " ..." ,
50+ "extra" : {
51+ "..." : " ..." ,
52+ "runtime" : {
53+ "dotenv_path" : " my_new_env_dir/.env"
54+ }
55+ }
56+ }
57+
58+ .. tip ::
59+
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.
67+
68+ For instance, you can do the following (starting Symfony ``5.3 ``)::
69+
70+ // bin/console
71+
72+ // ...
73+ $_SERVER['APP_RUNTIME_OPTIONS']['dotenv_path'] = 'my_new_console_env_dir/.env';
74+
75+ require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
76+ // ...
77+
78+ And/or::
79+
80+ // public/index.php
81+
82+ // ...
83+ $_SERVER['APP_RUNTIME_OPTIONS']['dotenv_path'] = 'my_new_web_env_dir/.env';
84+
85+ require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
86+ // ...
87+
2988
3089.. _override-config-dir :
3190
You can’t perform that action at this time.
0 commit comments