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

ActiveLibrary

lazervel/dotenv
===============

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

v2.0.1(2mo ago)3093↓100%14MITPHPPHP ^7.2 || ^8.0CI passing

Since Jul 23Pushed 2mo ago10 watchersCompare

[ Source](https://github.com/lazervel/dotenv)[ Packagist](https://packagist.org/packages/lazervel/dotenv)[ RSS](/packages/lazervel-dotenv/feed)WikiDiscussions main Synced today

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

PHP Dotenv
==========

[](#php-dotenv)

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

[![Banner](https://raw.githubusercontent.com/lazervel/assets/main/banners/dotenv.png)](https://raw.githubusercontent.com/lazervel/assets/main/banners/dotenv.png)

[![](https://camo.githubusercontent.com/a14ab1cda443102b95b1c80a8c6a37c1adca26e3b530108cb1288d248598b223/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f417574686f722d496e6469616e2532304d6f6461737369722d2532333434636331313f7374796c653d666c61742d737175617265)](https://github.com/indianmodassir)[![](https://camo.githubusercontent.com/850776eaf64711769cd995180b0b1b8e0505a90a8970dfeba229d79e60f1e19c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6c617a657276656c2f646f74656e763f7374796c653d666c61742d737175617265)](LICENSE)[![Total Downloads](https://camo.githubusercontent.com/551928135f61b4cfdbd4bda559147f1a738746424d763b774abec7fadb144fd9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c617a657276656c2f646f74656e762e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lazervel/dotenv)[![](https://camo.githubusercontent.com/422a7c7a3262b5b09983e4c11253044566ef26a099567e5f07306773029f4471/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6c617a657276656c2f646f74656e763f7374796c653d666c61742d737175617265)](https://github.com/lazervel/dotenv/stargazers)[![Latest Version](https://camo.githubusercontent.com/82e68007dc72bda0bd2322e174ad8685fbf2c71785b6add14424e6d745365f33/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6c617a657276656c2f646f74656e762e7376673f7374796c653d666c61742d737175617265)](https://github.com/lazervel/dotenv/releases)

Installation
============

[](#installation)

Installation is super-easy via [Composer](https://getcomposer.org/)

```
composer require lazervel/dotenv
```

or add it by hand to your `composer.json` file.

Usage
-----

[](#usage)

```
use Lazervel\Dotenv\Dotenv;
require 'vendor/autoload.php';
```

If already .env file existing on current directory

```
$dotenv = Dotenv::process(__DIR__);
$dotenv->load();
```

If already .env file existing on current directory without throwing error

```
$dotenv = Dotenv::process(__DIR__);
$dotenv->safeLoad();
```

If already .env file existing on current directory

```
$dotenv = Dotenv::process(__DIR__, 'myconfig.env');
$dotenv->load();
```

Loads multiple `.env` files.

```
$dotenv = Dotenv::process(__DIR__, ['.env.local', '.env.example', '.env'], false);
$dotenv->load();
```

All of the defined variables are now available in the `$_ENV` and `$_SERVER` super-globals.

```
$s3_bucket = $_ENV['S3_BUCKET'];
$s3_bucket = $_SERVER['S3_BUCKET'];
```

Nesting Variables
-----------------

[](#nesting-variables)

It's possible to nest an environment variable within another, useful to cut down on repetition.

This is done by wrapping an existing environment variable in `${…}` e.g.

```
BASE_DIR="/var/webroot/project-root"
CACHE_DIR="${BASE_DIR}/cache"
TMP_DIR="${BASE_DIR}/tmp"
```

Requiring Variables to be Set
-----------------------------

[](#requiring-variables-to-be-set)

PHP dotenv has built in validation functionality, including for enforcing the presence of an environment variable. This is particularly useful to let people know any explicit required variables that your app will not work without.

You can use a single string:

```
$dotenv->required('DATABASE_DSN');
```

Or an array of strings:

```
$dotenv->required(['DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS']);
```

Security
--------

[](#security)

If you discover a security vulnerability within this package, please send an email to  All security vulnerabilities will be promptly addressed. You may view our full security policy [here](https://github.com/lazervel/dotenv/security/policy).

License
-------

[](#license)

PHP dotenv is licensed under [MIT License](https://github.com/lazervel/dotenv/blob/main/LICENSE).

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance87

Actively maintained with recent releases

Popularity24

Limited adoption so far

Community24

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 77.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 ~60 days

Total

4

Last Release

62d ago

Major Versions

v1.0.0 → v2.0.02025-10-19

### Community

Maintainers

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

---

Top Contributors

[![indianmodassir](https://avatars.githubusercontent.com/u/152081666?v=4)](https://github.com/indianmodassir "indianmodassir (76 commits)")[![shahzadiafsu](https://avatars.githubusercontent.com/u/182284120?v=4)](https://github.com/shahzadiafsu "shahzadiafsu (6 commits)")[![shahzada967](https://avatars.githubusercontent.com/u/226899880?v=4)](https://github.com/shahzada967 "shahzada967 (3 commits)")[![proshamiya](https://avatars.githubusercontent.com/u/184147656?v=4)](https://github.com/proshamiya "proshamiya (2 commits)")[![jsbit530](https://avatars.githubusercontent.com/u/185949222?v=4)](https://github.com/jsbit530 "jsbit530 (1 commits)")[![modassirdev](https://avatars.githubusercontent.com/u/186417509?v=4)](https://github.com/modassirdev "modassirdev (1 commits)")[![ngdadnf](https://avatars.githubusercontent.com/u/186187994?v=4)](https://github.com/ngdadnf "ngdadnf (1 commits)")[![phpexp](https://avatars.githubusercontent.com/u/186431947?v=4)](https://github.com/phpexp "phpexp (1 commits)")[![promodassir](https://avatars.githubusercontent.com/u/121736316?v=4)](https://github.com/promodassir "promodassir (1 commits)")[![shahilsx](https://avatars.githubusercontent.com/u/187042373?v=4)](https://github.com/shahilsx "shahilsx (1 commits)")[![authmodassir](https://avatars.githubusercontent.com/u/186814361?v=4)](https://github.com/authmodassir "authmodassir (1 commits)")[![sidraham](https://avatars.githubusercontent.com/u/185451793?v=4)](https://github.com/sidraham "sidraham (1 commits)")[![codingwallah57](https://avatars.githubusercontent.com/u/186148228?v=4)](https://github.com/codingwallah57 "codingwallah57 (1 commits)")[![itzjuli](https://avatars.githubusercontent.com/u/186119370?v=4)](https://github.com/itzjuli "itzjuli (1 commits)")[![johnadam57](https://avatars.githubusercontent.com/u/186262548?v=4)](https://github.com/johnadam57 "johnadam57 (1 commits)")

---

Tags

dotenvenvphpdotenvenvdotenvenvloader

### Embed Badge

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

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

###  Alternatives

[vlucas/phpdotenv

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

13.5k591.0M4.8k](/packages/vlucas-phpdotenv)[symfony/dotenv

Registers environment variables from a .env file

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

Makes it possible to set environment variables for composer projects.

1634.4M31](/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.

6111.7M19](/packages/m1-env)[sroze/companienv

Companion for .env files

246416.9k1](/packages/sroze-companienv)[johnathanmiller/secure-env-php

Encrypt environment files for production use.

6053.5k2](/packages/johnathanmiller-secure-env-php)

PHPackages © 2026

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