Understanding the .env file

Published

Updated

.env

Keep production clean.

A .env file holds ENV vars for local development. On fortrabbit, set them in the dashboard instead and keep the .env file out of git and off the server.

The .env file

A .env file is a plain text file at the project root with one KEY=value pair per line. PHP does not read it by itself, a parser library loads it:

Laravel, Symfony and Craft CMS ship with a parser and a .env file.

Keep .env files off the server

Set ENV vars on fortrabbit in the dashboard. A .env file on the server adds a second source of configuration: depending on the parser, its values override the dashboard values or the other way round. Pick one, the dashboard is the recommended one.

Keep secrets out of git. Laravel and Craft CMS list .env in their .gitignore. Symfony commits .env with defaults and ignores .env.local, which holds the local secrets. See ENV var security.

Written by humans and AI in collaboration.

AI use & editorial processEdit on GitHub ↗