PHPackages                             melbahja/environ - 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. melbahja/environ

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

melbahja/environ
================

Load environment variables from .env file ONLY on $\_ENV and runtime.

v1.1.0(5y ago)10222MITPHPPHP &gt;=7.1

Since Sep 23Pushed 4y ago2 watchersCompare

[ Source](https://github.com/melbahja/environ)[ Packagist](https://packagist.org/packages/melbahja/environ)[ RSS](/packages/melbahja-environ/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

Environ
=======

[](#environ)

Load PHP environment variables from .env (INI syntax) file only on `$_ENV` and runtime.

[![](environ.jpg?raw=true)](environ.jpg?raw=true)[![Build Status](https://camo.githubusercontent.com/e67aafc6a02b5094a880967a094e93bdb7a9424e69d16bb1a835d682cf9819b1/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6d656c6261686a612f656e7669726f6e2f6d61737465722e737667)](https://travis-ci.org/melbahja/environ)[![Twitter](https://camo.githubusercontent.com/08abab730b0af65b3384a3a7e491208336449600875348061a3920d5bb38f8a1/68747470733a2f2f696d672e736869656c64732e696f2f747769747465722f75726c2f68747470732f6769746875622e636f6d2f6d656c6261686a612f656e7669726f6e2e7376673f7374796c653d736f6369616c)](https://twitter.com/intent/tweet?text=Wow:&url=https%3A%2F%2Fgithub.com%2Fmelbahja%2Fenviron)

Installation :
--------------

[](#installation-)

```
composer require melbahja/environ
```

Why?
----

[](#why)

Some env libraries load variables into `$_SERVER` and `$_REQUEST`, which is a stupid idea that can lead to expose credentials and insert sensitive information into log files. `environ` only load variables to superglobal `$_ENV` and runtime via `putenv`.

Usage :
-------

[](#usage-)

`/path/to/your/project/.env`

```
; set a var
APP_MODE = "dev"

; array
[DATABASE]
HOST = '127.0.0.1'
USERNAME = 'root'
PASSWORD = null
```

YourScript.php

```
require 'vendor/autoload.php';

use Melbahja\Environ\Environ;

// environ looking for .env or env.ini file in your directory
Environ::load('/path/to/your/project');

var_dump(Environ::get('APP_MODE')); // string

var_dump(Environ::get('DATABASE')); // array

var_dump($_ENV['DATABASE']); // array
```

### Note:

[](#note)

Arrays will not be available in `getenv()`, you can only access them via `$_ENV` or `Environ::get()`.

Helper
------

[](#helper)

```
  # if you want a helper
  function env(string $var, $default = null)
  {
    return \Melbahja\Environ\Environ::get($var, $default);
  }
```

Environ methods :
-----------------

[](#environ-methods-)

```
Environ::load(string $directory): bool
```

```
Environ::get(string $var, $default = null): mixed
```

```
Environ::set(string $var, $value): bool
```

```
# Example: Environ::is('apache'), Environ::is('cli')
Environ::is(string $sapi): bool
```

License :
---------

[](#license-)

[MIT](https://github.com/melbahja/environ/blob/master/LICENSE) Copyright (c) 2018-present Mohamed Elbahja

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 89.5% 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 ~333 days

Total

3

Last Release

2125d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/67b45037a03b3a6ed6cc118eb636a3cc544366594e8dc460f9f87fe30dc6bd6b?d=identicon)[melbahja](/maintainers/melbahja)

---

Top Contributors

[![melbahja](https://avatars.githubusercontent.com/u/8259014?v=4)](https://github.com/melbahja "melbahja (17 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (2 commits)")

---

Tags

envenvironmentenvironment-variablesenvironment-varsiniphpphp-environment-loaderphp7php71php72environmentenvPHP7inienv-loaderenv variables

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/melbahja-environ/health.svg)

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

###  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)[imliam/laravel-env-set-command

Set a .env file variable from the command line

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

Laravel env helper commands

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

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

5884.0k7](/packages/cekurte-environment)[mirazmac/dotenvwriter

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

19129.3k7](/packages/mirazmac-dotenvwriter)

PHPackages © 2026

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