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

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

rayanlevert/dotenv
==================

Dependency-free environment file handler (.env) loading variables and its values in $\_ENV, $\_SERVER and getenv() in the PHP userland

v3.0.1(1y ago)130[1 issues](https://github.com/rayanlevert/dotenv/issues)BSD-3-ClausePHPPHP &gt;=8.4CI passing

Since Oct 19Pushed 9mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (3)Versions (23)Used By (0)

Simple, dependency-free and fast class handling an environment file to `$_ENV`, `$_SERVER` and `getenv()`
---------------------------------------------------------------------------------------------------------

[](#simple-dependency-free-and-fast-class-handling-an-environment-file-to-_env-_server-and-getenv)

[![Packagist Version](https://camo.githubusercontent.com/cf77b9f2ff3efc2656208e36edfe9727df661ec489415c51628697163e714630/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726179616e6c65766572742f646f74656e76)](https://packagist.org/packages/rayanlevert/dotenv)[![PHP from Packagist](https://camo.githubusercontent.com/a16b1c74e5a7ec3d78d84cb472efce187fefefe2961f6b0c8a0b418d1b4a9df6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f726179616e6c65766572742f646f74656e76)](https://packagist.org/packages/rayanlevert/dotenv)[![codecov](https://camo.githubusercontent.com/b0a11b0770c8578a2243263f02adf1bd41bb95cde81028c8ced0ca08f2d32d24/68747470733a2f2f636f6465636f762e696f2f67682f726179616e6c65766572742f646f74656e762f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/rayanlevert/dotenv)

> Version &gt;= 3.0 supports only php8.4 with all brand new features, for &gt;= php8.1, version 2.0 is still supported.

### Initializes the instance setting the file path

[](#initializes-the-instance-setting-the-file-path)

```
$oDotenv = new \RayanLevert\Dotenv\Dotenv('/file/to/.dotenv');
```

An exception `RayanLevert\Dotenv\Exception` will be thrown if the file is not readable

### Reads the file content and loads in `$_ENV`, `$_SERVER` et `getenv()`, values of each variable

[](#reads-the-file-content-and-loads-in-_env-_server-et-getenv-values-of-each-variable)

```
$oDotenv->load();
```

#### For each new line found, tries to set to the name of the variable its value after the `=` sign

[](#for-each-new-line-found-tries-to-set-to-the-name-of-the-variable-its-value-after-the--sign)

```
TEST_VALUE1=value1 => $_ENV['TEST_VALUE1'] = value1

```

If the value is a primitive value, the value will be casted to the `PHP` userland
---------------------------------------------------------------------------------

[](#if-the-value-is-a-primitive-value-the-value-will-be-casted-to-the-php-userland)

```
NAME=1 => $_ENV['NAME'] = 1
NAME=23.34 => $_ENV['NAME'] = 23.34 (float values will be casted only with a dot .)
NAME=true => $_ENV['NAME'] = true
NAME=false => $_ENV['NAME'] = false
NAME=string value => $_ENV['NAME'] = 'string value'
```

### Multiline variables are also available ! (separated by `\n`), double quotes (`"`) will be used

[](#multiline-variables-are-also-available--separated-by-n-double-quotes--will-be-used)

```
    NAME="This is a variable
    with
    multiple
    lines"
```

### Nested variables, declared beforehand via the same file or `getenv()` (set via the OS or docker for example)

[](#nested-variables-declared-beforehand-via-the-same-file-or-getenv-set-via-the-os-or-docker-for-example)

```
    NESTED=VALUE
    NAME=${NESTED}
    NAME2=${NESTED}/path

    $_ENV['NESTED'] = 'VALUE'
    $_ENV['NAME'] = 'VALUE'
    $_ENV['NAME2'] = 'VALUE/path'
```

Throw an `RayanLevert\Dotenv\Exception` if at least one variable is not present in the `$_ENV` superglobal

```
$oDotenv->required('FIRST_REQUIRED', 'SECOND_REQUIRED');
```

Worth if we want required variables for application purposes, an exception will be thrown to prevent some logic error

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance30

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 69.6% 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 ~54 days

Recently: every ~23 days

Total

20

Last Release

275d ago

Major Versions

v1.3.1 → v2.0.02023-12-01

v2.1.0 → 3.0.02025-01-01

v2.2.1 → 3.0.x-dev2025-06-06

PHP version history (4 changes)v1.0.0PHP &gt;=7.3

v1.1.0PHP ^8.0

v1.1.1PHP &gt;=8.1

3.0.0PHP &gt;=8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/7253402d616a4792e6733113363a7f6918d318fb2b68fce60e5eb6d715319d69?d=identicon)[rayanlevert](/maintainers/rayanlevert)

---

Top Contributors

[![rayanlevert](https://avatars.githubusercontent.com/u/78140431?v=4)](https://github.com/rayanlevert "rayanlevert (39 commits)")[![rlevert-dis](https://avatars.githubusercontent.com/u/83226311?v=4)](https://github.com/rlevert-dis "rlevert-dis (17 commits)")

---

Tags

dependency-freedotenvdotenv-loaderdotenv-parserphpphpenvdotenv

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[vlucas/phpdotenv

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

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

PHPackages © 2026

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