talira

PHP dotenv

Loads environment variables from .env to $_ENV and $_SERVER automagically

open sourceBSD-3-Clausefree

PHP dotenv loads environment variables from a .env file into $_ENV and $_SERVER, and optionally into getenv() and putenv(), so configuration such as database credentials stays out of the code and works the same under Apache, Nginx, the CLI and PHP's built-in server. It supports immutable loading, several files, nested variable references and built-in validation of required variables. It is a PHP version of Ruby's dotenv.

Problems it solves

  • load settings from a .env file in a PHP app
  • keep database credentials out of my PHP code
  • fail early when a required environment variable is missing in PHP

Features

  • loads .env into $_ENV and $_SERVER
  • optional getenv() and putenv() support
  • immutable loading and multiple files
  • nested variable references
  • validation of required variables