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

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

fkrzski/dotenv
==============

Library that adds the ability to access variables from '.env', $\_ENV, and $\_SERVER using the getenv() function

V1.1.0(4y ago)25MITPHPPHP &gt;=7.0

Since Jan 26Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/fkrzski/Dotenv)[ Packagist](https://packagist.org/packages/fkrzski/dotenv)[ Docs](https://github.com/fkrzski/Dotenv)[ RSS](/packages/fkrzski-dotenv/feed)WikiDiscussions master Synced today

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

Dotenv
======

[](#dotenv)

Library that adds the ability to access variables from '.env', $\_ENV, and $\_SERVER using the getenv() function

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

[](#installation)

```
composer require fkrzski/dotenv
```

Usage
=====

[](#usage)

### Basics

[](#basics)

Add your application configuration variables to `.env` file in your project. Next add `.env` to `.gitignore` file! You should create a `.env.example` file to have a skeleton with variable names for your contributors

```
APP_NAME="My App Name"  # My app name
API_KEY=YourApiKey      # My api key
```

### Include `Dotenv` class

[](#include-dotenv-class)

```
use Dotenv\Dotenv;
```

### Load `.env` variables

[](#load-env-variables)

```
$dotenv = new Dotenv('.env');
$dotenv->start();
```

### Custom path or file name

[](#custom-path-or-file-name)

```
$dotenv = new Dotenv('path/to/file/myenvfile.env');

// Now you are using myenvfile.env from /path/to/file folder
```

### Many `.env` files

[](#many-env-files)

```
$dotenv = new Dotenv('path/to/file/myenvfile.env', 'path/to/file/mysecondenvfile.env');
```

### Retrieving variables values

[](#retrieving-variables-values)

```
echo getenv('APP_NAME');
echo $_SERVER['APP_NAME'];
echo $_ENV['APP_NAME'];

// output: My App Name
```

### Overwrtitting a variable

[](#overwrtitting-a-variable)

`.env` file

```
APP_NAME="App Name"
API_KEY=ApiKey

APP_NAME="Second App Name"
API_KEY=SecondApiKey
```

PHP file

```
$dotenv->start(['APP_NAME']);

echo getenv('APP_NAME');
echo getenv('API_KEY');

// Output:
// Second App Name
// ApiKey
```

Second possibility `.env` file

```
APP_NAME="App Name"
API_KEY=ApiKey

APP_NAME="Second App Name"
API_KEY=SecondApiKey
```

PHP file

```
$dotenv->start(['*']);

echo getenv('APP_NAME');
echo getenv('API_KEY');

// Output:
// Second App Name
// SecondApiKey
```

### Validating and requiring variables

[](#validating-and-requiring-variables)

`.env` file

```
APP_NAME="App Name"
PHONE_NUMBER=111222333
```

PHP file

```
$dotenv->start();

$dotenv->validator()->validate([
    'APP_NAME'     => 'required|alnum',
    'PHONE_NUMBER' => 'required|integer',
]);

/* All validating rules:
 * - required
 * - letters (Letters and spaces only)
 * - alnum (Letters, numers and spaces)
 * - integer
 * - boolean (true/false)
 * - float
 */
```

### Put single variable

[](#put-single-variable)

```
Dotenv::single('VAR', 'value');
echo getenv("VAR");
```

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance46

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

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

4

Last Release

1613d ago

### Community

Maintainers

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

---

Top Contributors

[![fkrzski](https://avatars.githubusercontent.com/u/75097934?v=4)](https://github.com/fkrzski "fkrzski (20 commits)")[![claude](https://avatars.githubusercontent.com/u/81847?v=4)](https://github.com/claude "claude (1 commits)")

---

Tags

configurationdotenvenvenvironmentenvironment-variablesphpenvironmentenvdotenvvariables

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[vlucas/phpdotenv

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

13.5k640.2M6.3k](/packages/vlucas-phpdotenv)[symfony/dotenv

Registers environment variables from a .env file

3.8k243.3M2.8k](/packages/symfony-dotenv)[imliam/laravel-env-set-command

Set a .env file variable from the command line

119359.7k10](/packages/imliam-laravel-env-set-command)[msztorc/laravel-env

Laravel env helper commands

7858.2k](/packages/msztorc-laravel-env)[cekurte/environment

A library to get the values from environment variables and process to php data types

5887.0k8](/packages/cekurte-environment)[mirazmac/dotenvwriter

A PHP library to write values to .env (DotEnv) files

21154.0k12](/packages/mirazmac-dotenvwriter)

PHPackages © 2026

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