November 19, 2018 Ryan Weaver

When Symfony 4.0 was released, the .env file was introduced as a way to set environment variables. The core of the system has not changed. But, thanks to recent updates to some core Symfony recipes, .env loading has some new features that can be enjoyed on any Symfony Flex project!

If you have an existing Symfony app (started before today), your app does not require any changes to keep working. But, if/when you are ready to take advantage of these improvements, you will need to make a few small updates.

What Changed Exactly?¶ But first, what changed? On a high-level, not much. Here's a summary of the most important changes: A) The .env.dist file no longer exists. Its contents should be moved to your .env file (see the next point).

file no longer exists. Its contents should be moved to your file (see the next point). B) The .env file is now committed to your repository. It was previously ignored via the .gitignore file (the updated recipe does not ignore this file). Because this file is committed, it should contain non-sensitive, default values. Basically, the .env.dist file was moved to .env .

file now committed to your repository. It was previously ignored via the file (the updated recipe does not ignore this file). Because this file is committed, it should contain non-sensitive, default values. Basically, the file was moved to . C) A .env.local file can now be created to override environment variables for your machine. This file is ignored in the new .gitignore .

file can now be created to override environment variables for your machine. This file is ignored in the new . D) When testing, your .env file is now read, making it consistent with all other environments. You can also create a .env.test file for test-environment overrides. Point (D) is one of the main motivations behind these changes: it makes setting and overriding environment variables for your test environment a delight. These improvements can be used in any Symfony Flex project (Symfony 3.4 or higher). Changes to the recipes (see below) make it possible to take advantage of the Symfony 4.2 feature - Define env vars per environment - in lower versions. To take advantage of these, you will need to modify a few files in your existing app.

Updating My Application¶ Updating your existing application is optional, but just requires modifying a few files. To update, see: DotEnv: Update my Application in the Symfony Docs.