Skip to content

Allow to set disable_dotenv via environment variable #60755

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

Open
danrot opened this issue Jun 11, 2025 · 0 comments
Open

Allow to set disable_dotenv via environment variable #60755

danrot opened this issue Jun 11, 2025 · 0 comments

Comments

@danrot
Copy link
Contributor

danrot commented Jun 11, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants