Skip to content

Solo DotenvStrict .env files. Predictable environment.

Read layered .env files as an array or load them into $_ENV. A broken file fails at startup with its name and line, and the server's own variables keep precedence.

Solo Dotenv

Load and read ​

dotenv
# .env
APP_ENV=production
APP_DEBUG=no
APP_PORT=8080
DB_DSN="pgsql:host=db;dbname=app"
php
use Solo\Dotenv\Dotenv;

Dotenv::load(__DIR__); // .env, then .env.local; both optional

$env = Dotenv::string('APP_ENV', 'local'); // 'production'
$debug = Dotenv::bool('APP_DEBUG');        // false
$port = Dotenv::int('APP_PORT', 8000);     // 8080
$dsn = Dotenv::required('DB_DSN');         // 'pgsql:host=db;dbname=app'

A variable the server already provides, such as APP_ENV set in a container, keeps its value. Read the getting-started guide and the API reference for layered files, precedence and errors.

Installation ​

PHP 8.3+ is required. The package has no runtime dependencies.

sh
composer require solophp/dotenv

Continue with the getting-started guide.

MIT licensed.