Loads environment variables from .env files to PHP's getenv(), $_ENV and $_SERVER automatically.
PHP dotenv is a PHP library that loads environment variables from `.env` files into PHP's superglobals (`$_ENV`, `$_SERVER`) and optionally `getenv()`. It enables developers to follow the twelve-factor app methodology by keeping sensitive configuration like API keys and database credentials out of code and in environment-specific files, ensuring portability across different deployment environments and simplifying configuration management.
PHP developers building applications that require secure, environment-specific configuration management, such as web applications, APIs, or CLI tools that need to separate sensitive credentials from source code.
Developers choose PHP dotenv because it provides a standardized, simple way to manage environment variables without modifying server configurations like Apache or Nginx virtual hosts, works across all PHP runtimes (Apache, Nginx, CLI, built-in webserver), and includes robust features like validation, nested variables, and immutability control.
Loads environment variables from .env to getenv(), $_ENV and $_SERVER automagically.
Loads variables from .env files directly into PHP's $_ENV and $_SERVER superglobals, eliminating the need to modify Apache or Nginx configurations, as highlighted in the README's 'Why .env?' section.
Provides built-in validation for required variables, empty checks, integer and boolean types, and allowed values, ensuring configuration integrity at application startup, as detailed in the 'Requiring Variables to be Set' section.
Allows variable interpolation within .env files using ${VAR} syntax, reducing repetition and improving maintainability, as explained in the 'Nesting Variables' part of the README.
Offers mutable and immutable loading options with customizable repositories, giving developers fine-grained control over whether existing environment variables can be overwritten, as described in the 'Immutability and Repository Customization' section.
Discourages using getenv() and putenv() due to thread safety issues, requiring the use of unsafe methods like createUnsafeImmutable for compatibility, which can be a concern in multi-threaded environments.
Requires collaborators to manually copy .env.example to .env and fill in values, adding an extra step in the onboarding process that isn't automated, as noted in the 'Usage' section.
Relies on PHP superglobals like $_ENV, which might be deactivated in certain server setups (e.g., shared hosting), necessitating changes to php.ini's variables_order, as mentioned in the 'Troubleshooting' section.
Major releases introduce breaking changes, requiring developers to follow upgrading guides (e.g., from V4 to V5), which can add maintenance burden for legacy projects.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.