- π¬π§United Kingdom alexpott πͺπΊπ
It would be lovely to use a .env to set environment variables for testing. This would make it much simpler to swap between Drupal 10 and 11 for testing purposes.
I propose we add the Symfony dotenv library as a dependency and use it to load files from the root directory of the project. We could add
// loads .env, .env.local, and .env.$APP_ENV.local or .env.$APP_ENV $dotenv->loadEnv(__DIR__.'/.env');
to core/tests/bootstrap.php so environment variables are available when testing and we could add it to \Drupal\Core\DrupalKernel::bootEnvironment() to ensure it is loaded when we boot.
This would allow consist environment management for Drupal core dev and projects built on Drupal.
- πΊπΈUnited States moshe weitzman Boston, MA
What I have seen is that .env files are helpful for local development, and less so for staging and prod servers which have other means of writing env variables. Given that we have standardized on DDEV for local dev, which already support setting env variables from config or .env files, do we really need this? The OP was written in an age before Docker based local dev.
- heddn Nicaragua
While ddev/docker does indeed support env variables natively, other hosting providers like Pantheon and the wild-west of bare metal and shared hosting do not have solutions in this space. Providing a core-supported option here might be the impetus for folks like Pantheon to switch from proprietary secrets text files to env variables.
I could easily see us taking the base added here and doing a lot of special things in follow-ups. Like injecting the DB credentials for the primary/default DB automatically. Or providing an env variable override process for settings and config. But the base logic/support would be needed first.
- πΊπΈUnited States moshe weitzman Boston, MA
That sounds like a feature request for Pantheon (if their workarounds are not sufficient). Acquia and Platform support setting env variables, as do things like .htaccess and nginx config.
Like I said, DotEnv is really made for local development, so all this talk of web hosting demonstrates how people will be confused if this goes in. If people really want this feature, its a composer require away.
I could easily see us taking the base added here and doing a lot of special things in follow-ups. Like injecting the DB credentials for the primary/default DB automatically. Or providing an env variable override process for settings and config. But the base logic/support would be needed first.
I'm totally on board with settings.php honoring env variables. IMO thats the first part to do, not the last.