Understanding the .env file
Reviewedbyfl
Markdown ↓.env
Keep production clean.
Local .env files store configuration variables for development. Learn what they are, why they're useful locally, and why to use the dashboard on fortrabbit instead.
The .env file
A .env file is a plain text configuration file stored at your project root that contains environment variable key-value pairs. It's easy to read and write, and runtime-agnostic. To use .env files, you need a parser library to read the file and expose the variables to your application. Here are the most popular parsers for PHP:
- github.com/vlucas/phpdotenv - Everyone
- github.com/symfony/dotenv - Symfony
Modern PHP frameworks like Laravel and Symfony and some CMS like Craft CMS use .env files for configuration and include a parser already.
Don't put .env files on the server
.env files are intended for local development only. Use pre-configured ENV vars from the fortrabbit dashboard instead, and add custom variables through the dashboard as well. Don't upload .env files to fortrabbit servers—this avoids confusion about conflicting configuration sources and enhances security.
Many CMS and frameworks will parse .env files automatically. Depending on how the parser is configured, ENV vars from the .env file may or may not override the values from the fortrabbit dashboard. To avoid conflicting settings, choose one approach: either use dashboard ENV vars (recommended) or use a .env file.
Don't include .env files in your Git repository for security reasons—they often contain secrets and sensitive configuration. You can manually create or upload a .env file via SSH/SFTP, or automate the process. If you do, you can remove custom ENV vars from the dashboard. See ENV var security for more details.