.env (Environment file)
Technology
The .env file (environment file) is a configuration file in the project root that stores environment-specific variables and sensitive data such as database credentials, API keys, application keys, and debug settings. It is typically not committed to version control (e.g. Git) so that secrets are not exposed.
In Laravel and many other frameworks, values from .env are loaded via
Spaces around the equals sign are optional. Comments start with
In Laravel and many other frameworks, values from .env are loaded via
getenv() or a central configuration (e.g. config()). Each line follows the format:KEY=valueSpaces around the equals sign are optional. Comments start with
#. The .env.example file serves as a template without real secrets and is shared with the project so that developers know which variables need to be set.Best practices
- Never commit .env to repositories.
- Use different .env files for local, staging, and production environments.
- Set sensitive values via the hosting system's environment variables where .env is not available.