PHPackages                             chillerlan/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. chillerlan/php-dotenv

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

chillerlan/php-dotenv
=====================

A simple .env loader - PHP 8.1+

3.0.1(2y ago)016.7k—0%16MITPHPPHP ^8.1

Since Sep 7Pushed 2y ago1 watchersCompare

[ Source](https://github.com/chillerlan/php-dotenv)[ Packagist](https://packagist.org/packages/chillerlan/php-dotenv)[ Docs](https://github.com/chillerlan/php-dotenv)[ Fund](https://www.paypal.com/donate?hosted_button_id=WLYUNAT9ZTJZ4)[ Fund](https://ko-fi.com/codemasher)[ RSS](/packages/chillerlan-php-dotenv/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (2)Versions (8)Used By (6)

php-dotenv
==========

[](#php-dotenv)

Loads contents from a `.env` file into the environment. PHP 8.1+

[![PHP Version Support](https://camo.githubusercontent.com/e5fed9e3c88c76130dceaa47e7bc8eeec5c3a5ab46e7d180626e2e383006341d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6368696c6c65726c616e2f7068702d646f74656e763f6c6f676f3d70687026636f6c6f723d383839324246)](https://www.php.net/supported-versions.php)[![version](https://camo.githubusercontent.com/7a2bbfa6c5debc07be0fd1102c6848524b1a1f26e5f5359bc2f882acfd01b479/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6368696c6c65726c616e2f7068702d646f74656e762e7376673f6c6f676f3d7061636b6167697374)](https://packagist.org/packages/chillerlan/php-dotenv)[![license](https://camo.githubusercontent.com/7ef8c201f51d46ef9f99f3d8cedf0ca0dd2b7ea846decc1c2fd7156d5c8dce60/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6368696c6c65726c616e2f7068702d646f74656e762e737667)](https://github.com/chillerlan/php-dotenv/blob/master/LICENSE)[![Coverage](https://camo.githubusercontent.com/a8753a3eaf8bb77861affbde9aa6ef16c47e898d29c07b555677c486ad138057/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6368696c6c65726c616e2f7068702d646f74656e762e7376673f6c6f676f3d636f6465636f76)](https://codecov.io/github/chillerlan/php-dotenv)[![Packagist downloads](https://camo.githubusercontent.com/43370bd988cb79f03651742e0842bc4e1ff27f10dd8b2ed6746dfc6695108b26/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6368696c6c65726c616e2f7068702d646f74656e762e7376673f6c6f676f3d7061636b6167697374)](https://packagist.org/packages/chillerlan/php-dotenv/stats)[![CI](https://github.com/chillerlan/php-dotenv/workflows/CI/badge.svg)](https://github.com/chillerlan/php-dotenv/actions?query=workflow%3A%22CI%22)

Documentation
=============

[](#documentation)

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

[](#installation)

**requires [composer](https://getcomposer.org)**

*composer.json* (note: replace `dev-main` with a [version constraint](https://getcomposer.org/doc/articles/versions.md#writing-version-constraints), e.g. `^3.0`)

```
{
	"require": {
		"php": "^8.1",
		"chillerlan/php-dotenv": "dev-main"
	}
}
```

Installation via terminal: `composer require chillerlan/php-dotenv`

Profit!

Usage
-----

[](#usage)

```
# example .env
FOO=bar
BAR=foo
WHAT=${BAR}-${FOO}

```

```
$env = new DotEnv(__DIR__.'/../config', '.env');
$env->load(['foo']); // foo is required

// get a variable
$foo = $_ENV['FOO']; // -> bar
$foo = $env->get('FOO'); // -> bar
$foo = $env->FOO; // -> bar

// dynamically set a variable
$env->set('foo', 'whatever');
$env->FOO = 'whatever';

$foo = $env->get('FOO'); // -> whatever
// ...

// variable substitution
$foo = $env->get('WHAT'); // -> foo-bar
```

```
// avoid the global environment
$env = (new DotEnv(__DIR__.'/../config', '.env', false))->load();

$foo = $_ENV['FOO']; // -> undefined
$foo = $env->get('FOO'); // -> bar
$foo = $env->FOO; // -> bar
```

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity75

Established project with proven stability

 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

Every ~334 days

Recently: every ~307 days

Total

7

Last Release

802d ago

Major Versions

1.0.0 → 2.0.02020-04-17

2.1.2 → 3.0.02024-03-05

PHP version history (4 changes)1.0.0PHP ^7.2

2.0.0PHP ^7.4

2.1.0PHP ^7.4 || ^8.0

3.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/ada3d048807a11e536645fb87da881170b18f34c0c61fa09e34807c5d79e0b89?d=identicon)[codemasher](/maintainers/codemasher)

---

Top Contributors

[![codemasher](https://avatars.githubusercontent.com/u/592497?v=4)](https://github.com/codemasher "codemasher (25 commits)")

---

Tags

dotenvdotenv-loaderenvenvironment-variablesphpphp-libraryphp7php8helperenvdotenv

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[vlucas/phpdotenv

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

13.5k602.4M5.4k](/packages/vlucas-phpdotenv)[symfony/dotenv

Registers environment variables from a .env file

3.8k226.7M2.3k](/packages/symfony-dotenv)[helhum/dotenv-connector

Makes it possible to set environment variables for composer projects.

1594.6M34](/packages/helhum-dotenv-connector)[m1/env

Env is a lightweight library bringing .env file parser compatibility to PHP. In short - it enables you to read .env files with PHP.

6412.0M21](/packages/m1-env)[sroze/companienv

Companion for .env files

245418.8k1](/packages/sroze-companienv)[bnomei/kirby3-dotenv

Kirby Plugin for environment variables from .env

4144.1k1](/packages/bnomei-kirby3-dotenv)

PHPackages © 2026

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