solophp / dotenv
Read layered .env files as an array or load them into the PHP environment.
v2.0.0
2026-11-01 21:27 UTC
Requires
- php: ^8.3
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.5
- squizlabs/php_codesniffer: ^3.10
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Strict .env loader for PHP. Read layered files as an array, or load them into $_ENV and read typed values back. A malformed line fails with its file and line before anything is applied; variables the server already provides keep precedence, and HTTP_* request headers never count as environment. No putenv(), no interpolation and no runtime dependencies.
Installation
composer require solophp/dotenv
Requires PHP 8.3+.
Example
# .env APP_DEBUG=no APP_PORT=8080 DB_DSN="sqlite:/srv/app/data.db"
use Solo\Dotenv\Dotenv; Dotenv::load(__DIR__); // .env, then .env.local; both optional $debug = Dotenv::bool('APP_DEBUG'); // false $port = Dotenv::int('APP_PORT', 8000); // 8080 $dsn = Dotenv::required('DB_DSN'); // 'sqlite:/srv/app/data.db'
Dotenv::read() returns the same values as an array without touching the environment, and EnvParser::parse() parses a string.
Documentation
- Getting Started
- Layered Files
- Precedence
- File Syntax
- Error Handling
- API Reference
- Behavior in Detail
- Upgrading from 1.x
- Changelog
License
MIT. See LICENSE.