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

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

gokhankurtulus/dotenv
=====================

A simple library to supply environment variables from `.env`.

1.0.0(2y ago)019MITPHPPHP ^7.4 || ^8.0 || ^8.1

Since Jul 7Pushed 2y ago1 watchersCompare

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

READMEChangelog (1)DependenciesVersions (2)Used By (0)

dotenv
======

[](#dotenv)

[![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![PHP Version](https://camo.githubusercontent.com/b43c9d6cd8939c4868f963284928566c4c35dd2da0725c027f95a3d62f2f0329/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e342532422d626c75652e737667)](https://camo.githubusercontent.com/b43c9d6cd8939c4868f963284928566c4c35dd2da0725c027f95a3d62f2f0329/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e342532422d626c75652e737667)[![Release](https://camo.githubusercontent.com/6a30ba505698a196dfc8aca92596021529c0ea310d9e333344761e048bec3149/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f676f6b68616e6b757274756c75732f646f74656e762e737667)](https://camo.githubusercontent.com/6a30ba505698a196dfc8aca92596021529c0ea310d9e333344761e048bec3149/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f676f6b68616e6b757274756c75732f646f74656e762e737667)

A simple library to supply environment variables from `.env`.

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

[](#installation)

You can install the Dotenv using [Composer](https://getcomposer.org/). Run the following command in your project's root directory:

```
composer require gokhankurtulus/dotenv
```

Usage
-----

[](#usage)

Example `.env` file;

```
EXAMPLE_KEY=mykey
EXAMPLE_SECRET=mysecret
DB_DRIVER=mysql
DB_TABLE=tablename
```

To use the Dotenv class in your PHP script, you need to include the Composer autoloader:

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

Example PHP file;

```
use Dotenv\Dotenv;

$dotenv = new Dotenv('.env');
// This will cause an \Exception because VERSION is not set on the environment file and raiseError is true by default.
$dotenv->required(['VERSION']);

// If you don't want to get exception you can pass false as second parameter
if (!$dotenv->required(['VERSION'], false));
    echo 'You have to set VERSION.';
echo $_ENV['EXAMPLE_KEY']; // Output: mykey
```

Securing the .env File
----------------------

[](#securing-the-env-file)

The `.env` file contains sensitive information such as database credentials, API keys, and other confidential data. It is important to secure the file and restrict access to prevent unauthorized exposure of this information. Here are some guidelines to consider:

1. File Placement: Place the `.env` file outside the public web directory or in a directory that is not directly accessible by the web server. This prevents direct access to the file via URL.
2. File Permissions: Set appropriate file permissions to ensure that only authorized users or processes can read the `.env` file. Restricting access to the file prevents unauthorized users from viewing its contents.
3. Gitignore: Add the `.env` file to your project's `.gitignore` file. This ensures that the file is not included in version control systems, preventing accidental exposure of sensitive information in your code repository.
4. Environment-specific Files: Consider using separate `.env` files for different environments (e.g., development, staging, production). This allows you to specify environment-specific configurations and reduces the risk of exposing sensitive credentials in non-production environments.
5. Encryption or Encoding: If required, you can encrypt or encode sensitive values within the `.env` file. This adds an extra layer of protection, and the values can be decrypted or decoded at runtime when they are needed.

Remember, the security of your application depends on properly safeguarding the sensitive information stored in the `.env` file. Regularly review and update the file, and ensure that access to it is limited to authorized individuals or processes.

**Note:** It is important to consult with a security professional and follow security best practices to ensure the confidentiality and integrity of your application's sensitive data.

License
-------

[](#license)

Dotenv is open-source software released under the [MIT License](LICENSE). Feel free to modify and use it in your projects.

Contributions
-------------

[](#contributions)

Contributions to Dotenv are welcome! If you find any issues or have suggestions for improvements, please create an issue or submit a pull request on the [GitHub repository](https://github.com/gokhankurtulus/dotenv).

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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

1045d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7a8dc07ce25345005f0d5c4e7eb9b9dc7348c25f9fe09375dcfe6950404f7e06?d=identicon)[gokhankurtulus](/maintainers/gokhankurtulus)

---

Top Contributors

[![gokhankurtulus](https://avatars.githubusercontent.com/u/43145716?v=4)](https://github.com/gokhankurtulus "gokhankurtulus (1 commits)")

---

Tags

dotenvenvenvdotenv

### Embed Badge

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

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

###  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)[helhum/dotenv-connector

Makes it possible to set environment variables for composer projects.

1594.6M34](/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.

6412.0M21](/packages/m1-env)[sroze/companienv

Companion for .env files

245418.8k1](/packages/sroze-companienv)[bnomei/kirby3-dotenv

Kirby Plugin for environment variables from .env

4144.1k1](/packages/bnomei-kirby3-dotenv)

PHPackages © 2026

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