PHPackages                             karamel/env - 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. karamel/env

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

karamel/env
===========

read .env file

v1.0.0(5y ago)23MITPHP

Since Oct 12Pushed 5y ago1 watchersCompare

[ Source](https://github.com/karamel-pack/env)[ Packagist](https://packagist.org/packages/karamel/env)[ RSS](/packages/karamel-env/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (2)Used By (0)

Karamel/Env
===========

[](#karamelenv)

Read environment variables throughout the project using the env() function

Why .env?
=========

[](#why-env)

You may need a config file in your PHP project that you can use to define your environment variables and use them throughout the project. You can use this package to meet your needs

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

[](#installation)

Installation is super-easy via Composer:

```
$ composer require karamel/env

```

Usage
-----

[](#usage)

After installing the package, call the setPath method in your project bootstrap file (or index.php file) to set the settings below

```
\Karamel\Env\Facade\Env::setPath("file",__DIR__."./.env");

```

In the above method : the first argument of the function determines the driver used, which (currently) must be equal to the value of the `file`.

The second argument also determines the address of your config file .

### contents of the config file

[](#contents-of-the-config-file)

The contents of the config file should be as follows :

```
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=site_shahreparche
DB_USERNAME=root
DB_PASSWORD=123456

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

```

In this file, the value before the symbol `=` key and the value after it is the value .

### Use config using the `env($key , $default = null)` method

[](#use-config-using-the-envkey--default--null-method)

The `env()` method is called as follows and accepts two inputs: The first input is equal to your desired key and the second value is equal to the default value, which is optional If your key is not in the .env file and you set the default value, the specified value will be returned to you .

### samples

[](#samples)

```
echo env("DB_CONNECTION")
// mysql
```

```
echo env("foo")
// NULL
```

```
echo env("foo","bar")
// bar
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

2045d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0b8d83a976fbf1c584d10a8483b56c6892e182fc819c7b00be46e8c0f1cf0ede?d=identicon)[amir\_kalantar](/maintainers/amir_kalantar)

---

Top Contributors

[![amir-kalantar](https://avatars.githubusercontent.com/u/19429628?v=4)](https://github.com/amir-kalantar "amir-kalantar (12 commits)")

---

Tags

configuration-filesdotenvenvphp

### Embed Badge

![Health badge](/badges/karamel-env/health.svg)

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

###  Alternatives

[voku/portable-utf8

Portable UTF-8 library - performance optimized (unicode) string functions for php.

52322.4M40](/packages/voku-portable-utf8)[xelson/flarum-ext-chat

Realtime Chat for Flarum!

229.7k](/packages/xelson-flarum-ext-chat)

PHPackages © 2026

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