Strict syntax
A malformed line, an invalid name or an unterminated quote raises ParseException with the file and line instead of being skipped. The message never contains the value.
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.
# .env
APP_ENV=production
APP_DEBUG=no
APP_PORT=8080
DB_DSN="pgsql:host=db;dbname=app"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.
PHP 8.3+ is required. The package has no runtime dependencies.
composer require solophp/dotenvContinue with the getting-started guide.