Skip to content

Add missing instructions to alter the environment directory #15608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion configuration/override_dir_structure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,66 @@ override it to create your own structure:
│ ├─ cache/
│ ├─ log/
│ └─ ...
└─ vendor/
├─ vendor/
└─ .env


.. _override-env-dir:

Override the Environment (DotEnv) Files Directory
-------------------------------------------------

Though the environment files directory is supposed to be the current project
root directory, you can actually set it via Composer or specifically in each
bootstrapper file ``index.php`` (your :ref:`front controller <from_flat_php-front-controller>`)
or your ``console`` file (located by default in the ``bin/`` directory of
your application).

You can change the ``runtime.dotenv_path`` option in the ``composer.json``
file:

.. code-block:: json

{
"...": "...",
"extra": {
"...": "...",
"runtime": {
"dotenv_path": "my_new_env_dir/.env"
}
}
}

.. tip::

Don't forget to update your Composer files (via ``composer update``, for instance),
so that the ``vendor/autoload_runtime.php`` files gets regenerated to reflect
your environment overrides for this.

If you want to set up different specific paths for your environment directories
for your console and web server calls, you'll have to use the PHP files to
achieve so, by altering the ``$_SERVER`` configuration.

For instance, you can do the following (starting Symfony ``5.3``)::

// bin/console

// ...
$_SERVER['APP_RUNTIME_OPTIONS']['dotenv_path'] = 'my_new_console_env_dir/.env';

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
// ...

And/or::

// public/index.php

// ...
$_SERVER['APP_RUNTIME_OPTIONS']['dotenv_path'] = 'my_new_web_env_dir/.env';

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
// ...


.. _override-config-dir:

Expand Down