Search by

solophp / dotenv

Vitaliy Olos

Read layered .env files as an array or load them into the PHP environment.

Package info

github.com/SoloPHP/Dotenv

pkg:composer/solophp/dotenv

Statistics

Installs: 67

Dependents: 2

Suggesters: 0

Stars: 0

Open Issues: 0

v2.0.0 2026-11-01 21:27 UTC

This package is auto-updated.

Last update: 2026-11-01 21:33:04 UTC


README

Latest Version on Packagist PHP Version License

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

Full Documentation

License

MIT. See LICENSE.