Kévin Dunglas
Contributed by Kévin Dunglas in #28533

Since the introduction of the DotEnv component in Symfony 3.3, we've been working hard to improve the experience of using env vars to configure Symfony apps. In Symfony 4.2, we've added a new loadForEnv() method to allow you define different env vars per environment.

Instead of creating a single .env file at your project's root dir, you can now create one or more env var files. The values for the env var are looked for in the following order:

  • .env.$APP_ENV.local (don't commit this file to the repository) defines environment-specific overrides for your local machine;
  • .env.$APP_ENV (commit this file to the repository) and defines environment-specific defaults for all developers/machines;
  • .env.local (don't commit this file to the repository) overrides the main .env config only for your local machine;
  • .env (commit this file to the repository) and defines the default values for the env vars used in the application.

We're working on a Symfony Flex recipe to bring this new feature into the full Symfony framework (see symfony/recipes #466). There's no need to change anything in your existing applications if you don't want to, but new projects will get the latest recipes versions, with the following changes:

  • .env renamed as .env.local (and "gitignored").
  • .env.dist renamed as .env (and committed to the shared repository).
Published in #Living on the edge