Description
Description
I have a Symfony application in which I want to load all the .env
files for local development, but not in the production environment, in which I handle those differently by using some tools offered by the cloud provider. So what I've ended up with is adding the following lines in public/index.php
and in bin/console
:
$_SERVER['APP_RUNTIME_OPTIONS'] = [
'disable_dotenv' => ($_SERVER['APP_ENV'] ?? null) === 'prod',
];
I find this quite cumbersome and it leads to duplicated code. Therefore I would suggest to introduce an environment variable, which is handled somehow by Symfony (e.g. the Runtime
component). Then I could just set this variable in our cloud environment. I would also be open to contribute this myself after receiving at least some guidance.
Example
I would suggest that instead of the above code I can set an environment variable to disable loading .env
files. E.g. something like this:
APP_DISABLE_DOTENV=1
With that variable being set to 1
.env
files would not be loaded, if it is set to 0
they are being loaded.