Dotenv files cascade override (.env.local, .env.testing, .env.testing.local) #58162
Unanswered
antonkomarev
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, Laravel relies primarily on a single
.envfile (and potentially a specific.env.testingfor tests). This file is typically git-ignored, requiring developers to manually copy.env.exampleto.envupon setting up the project.While functional, this approach lacks granularity. Changes to configuration defaults require every developer to manually update their ignored
.envfiles. Furthermore, overriding specific testing configurations locally often leads to accidental modifications of shared files or requires complex CI/CD scripting to swap files.Adopting the Symfony-style cascading configuration (using
.env,.env.local,.env.[environment],.env.[environment].local) would significantly improve Developer Experience (DX) and deployment workflows.Current package supports this feature:
Key benefit: Separation of Secrets and Config
Usage: Secrets (API keys, DB passwords) go into
.env.local, which is git-ignored. Defaults go into.env.Benefit: This cleanly separates configuration structure (tracked in Git) from sensitive credentials (kept local), reducing the risk of accidentally committing secrets.
Sidenotes
In Symfony test environments ignores
.env.localfile, but other environments use it as well.Example:
.env -> .env.testing -> .env.testing.local.env -> .env.local -> .env.testing -> .env.testing.localHow it might look like
.env (commited to repo)
.env.local (git ignored)
.env.stage.local (git ignored)
.env.test.local (git ignored)
Compiled at runtime .env will look like:
Beta Was this translation helpful? Give feedback.
All reactions