PHPackages                             solophp/dotenv - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. solophp/dotenv

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

solophp/dotenv
==============

Simple, zero-dependency .env loader for PHP. Loads files into $\_ENV with optional $\_SERVER population.

v1.0.0(9mo ago)016MITPHPPHP ^8.0

Since Aug 19Pushed 9mo agoCompare

[ Source](https://github.com/SoloPHP/Dotenv)[ Packagist](https://packagist.org/packages/solophp/dotenv)[ RSS](/packages/solophp-dotenv/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Solo Dotenv
===========

[](#solo-dotenv)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d99a0a7cf1f262e5517f97be77b2737b7ab32ed69c0d56104500d06224149d58/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736f6c6f7068702f646f74656e762e737667)](https://packagist.org/packages/solophp/dotenv)[![License](https://camo.githubusercontent.com/6bd66f692cc2a9611c049c9b4edb811011851505bd66f351845be6c3e80c7425/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f736f6c6f7068702f646f74656e762e737667)](https://github.com/solophp/dotenv/blob/main/LICENSE)[![PHP Version](https://camo.githubusercontent.com/36b4c0ccc766168ff311b95a0d60df671ebc140ab5a9eafcf116b22a40b29ba9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f736f6c6f7068702f646f74656e762e737667)](https://packagist.org/packages/solophp/dotenv)

Simple, zero-dependency .env loader for PHP. Loads environment variables from files into `$_ENV` (optionally also `$_SERVER`). No global `putenv` calls, no magic variable expansion.

### Features

[](#features)

- **Small and focused**: just parsing and loading
- **Zero dependencies**
- **Deterministic overrides**: later files in the same call override earlier ones
- **Typed accessors**: `string`, `int`, `bool`, and `required`

### Installation

[](#installation)

```
composer require solophp/dotenv
```

### Quick start

[](#quick-start)

```
use Solo\Dotenv\Dotenv;

Dotenv::load(__DIR__, ['.env', '.env.local']);

$dbDsn = Dotenv::required('DB_DSN');
$isDebug = Dotenv::bool('APP_DEBUG', false);
```

### API

[](#api)

- `Dotenv::load(string $baseDir, array $filenames = ['.env', '.env.local'], bool $overwrite = false, bool $populateServer = false): void`
    - Loads files in order. Existing environment variables set before the call are preserved by default. Variables set by earlier files in the same call can be overridden by later files.
    - Set `$overwrite = true` to overwrite any existing `$_ENV` values.
    - Set `$populateServer = true` to mirror values into `$_SERVER`.
- `Dotenv::get(string $key, mixed $default = null): mixed`
- `Dotenv::string(string $key, string $default = ''): string`
- `Dotenv::int(string $key, int $default = 0): int`
- `Dotenv::bool(string $key, bool $default = false): bool`
- `Dotenv::required(string $key): string` — throws `InvalidArgumentException` if missing/empty.

### Parser

[](#parser)

The parser is implemented in `Solo\Dotenv\EnvParser` and supports:

- Lines like `KEY=VALUE`
- Optional leading `export `
- Single and double quotes
- Inline comments for unquoted values (`FOO=bar # comment`)
- No variable expansion (by design)

### Testing

[](#testing)

```
composer install
composer test
```

### License

[](#license)

MIT

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance58

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

272d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2f29817cec408d033cd4441c8f760e3ae40248dc0f66856a09080d282aee6959?d=identicon)[Vitaliy Olos](/maintainers/Vitaliy%20Olos)

---

Top Contributors

[![SoloPHP](https://avatars.githubusercontent.com/u/175482616?v=4)](https://github.com/SoloPHP "SoloPHP (1 commits)")

---

Tags

psrphpenvdotenvphp8strict types

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/solophp-dotenv/health.svg)

```
[![Health](https://phpackages.com/badges/solophp-dotenv/health.svg)](https://phpackages.com/packages/solophp-dotenv)
```

###  Alternatives

[lctrs/psalm-psr-container-plugin

Let Psalm understand better psr11 containers

17648.1k13](/packages/lctrs-psalm-psr-container-plugin)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
