PHPackages                             ez-php/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. ez-php/dotenv

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ez-php/dotenv
=============

Lightweight .env file loader for PHP — supports quoted values, variable interpolation, and immutable loading

1.11.0(1mo ago)03.7k↓90%1MITPHPPHP ^8.5CI passing

Since Mar 14Pushed 1mo agoCompare

[ Source](https://github.com/ez-php/dotenv)[ Packagist](https://packagist.org/packages/ez-php/dotenv)[ Docs](https://github.com/ez-php/dotenv)[ RSS](/packages/ez-php-dotenv/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (14)Versions (41)Used By (1)

ez-php/dotenv
=============

[](#ez-phpdotenv)

Lightweight `.env` file loader for PHP — supports quoted values, variable interpolation, and immutable loading. Zero dependencies.

[![CI](https://github.com/ez-php/dotenv/actions/workflows/ci.yml/badge.svg)](https://github.com/ez-php/dotenv/actions/workflows/ci.yml)[![Coverage](https://camo.githubusercontent.com/c999b3158afdad9bab35cab2f5e3e34e513bc1b013514a273462ac2867bb05f6/68747470733a2f2f636f6465636f762e696f2f67682f657a2d7068702f646f74656e762f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/ez-php/dotenv)

Requirements
------------

[](#requirements)

- PHP 8.5+

Installation
------------

[](#installation)

```
composer require ez-php/dotenv
```

Usage
-----

[](#usage)

```
use EzPhp\Env\Dotenv;

// Load .env from the project root (immutable — never overwrites existing env vars)
Dotenv::createImmutable(__DIR__)->load();

// Silently skip if the file doesn't exist (useful in production)
Dotenv::createImmutable(__DIR__)->safeLoad();

// Custom filename
Dotenv::createImmutable(__DIR__, '.env.testing')->load();
```

Variables are written to `$_ENV`, `$_SERVER`, and `getenv()`.

Supported syntax
----------------

[](#supported-syntax)

```
# Comments are ignored
APP_NAME=My App
APP_ENV=production

# Quoted values preserve whitespace and support escapes
GREETING="Hello, World!\nWelcome."

# Single-quoted values are literal — no interpolation, no escapes
LITERAL='value with $dollar and \n backslash'

# Variable interpolation in double-quoted values
BASE_URL=https://example.com
API_URL="${BASE_URL}/api/v1"

# export prefix is stripped
export SECRET_KEY=abc123

# Empty values
EMPTY=
```

Immutability
------------

[](#immutability)

Variables already present in the environment (set before loading) are never overwritten. This means real environment variables (e.g. set in Docker or CI) always take precedence over `.env` file values.

Parser
------

[](#parser)

`Parser` is the internal class that turns raw `.env` file content into a flat `array` map. You can use it directly if you want to parse `.env` content without writing to the environment:

```
use EzPhp\Env\Parser;

$vars = (new Parser())->parse(file_get_contents('.env'));
// ['APP_NAME' => 'My App', 'APP_ENV' => 'production', ...]
```

All syntax forms are supported: unquoted, double-quoted (escape sequences + interpolation), single-quoted (literal), empty values, `export` prefix, and inline comments.

License
-------

[](#license)

MIT — [Andreas Uretschnig](mailto:andreas.uretschnig@gmail.com)

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance91

Actively maintained with recent releases

Popularity22

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 89.9% 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

Every ~1 days

Total

40

Last Release

44d ago

Major Versions

0.9.3 → 1.0.02026-03-24

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/122030400?v=4)[AU9500](/maintainers/AU9500)[@AU9500](https://github.com/AU9500)

---

Top Contributors

[![AU9500](https://avatars.githubusercontent.com/u/122030400?v=4)](https://github.com/AU9500 "AU9500 (107 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (12 commits)")

---

Tags

phpconfigenvironmentenvdotenv

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[vlucas/phpdotenv

Loads environment variables from `.env` to `getenv()`, `$\_ENV` and `$\_SERVER` automagically.

13.5k627.3M6.1k](/packages/vlucas-phpdotenv)

PHPackages © 2026

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