PHPackages                             yannoff/composer-dotenv-handler - 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. yannoff/composer-dotenv-handler

ActiveLibrary

yannoff/composer-dotenv-handler
===============================

Composer script to generate .env file against .env.dist template

1.2.4(4y ago)02.2k↓100%1MITPHPPHP ^5.6|&gt;=7.0.8

Since Feb 15Pushed 4y ago1 watchersCompare

[ Source](https://github.com/yannoff/composer-dotenv-handler)[ Packagist](https://packagist.org/packages/yannoff/composer-dotenv-handler)[ Docs](https://github.com/yannoff/composer-dotenv-handler)[ RSS](/packages/yannoff-composer-dotenv-handler/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (12)Used By (0)

yannoff/composer-dotenv-handler
===============================

[](#yannoffcomposer-dotenv-handler)

[![Latest Stable Version](https://camo.githubusercontent.com/a8d26afee47f86338dc15b87f5a70cf48f252ce9508bf74f0b173841ab1def1e/68747470733a2f2f706f7365722e707567782e6f72672f79616e6e6f66662f636f6d706f7365722d646f74656e762d68616e646c65722f762f737461626c65)](https://packagist.org/packages/yannoff/composer-dotenv-handler)[![Total Downloads](https://camo.githubusercontent.com/12bc6715d79ca93944241d2f8b74410b03a7d4398857085f0c92f82919489aff/68747470733a2f2f706f7365722e707567782e6f72672f79616e6e6f66662f636f6d706f7365722d646f74656e762d68616e646c65722f646f776e6c6f616473)](https://packagist.org/packages/yannoff/composer-dotenv-handler)[![License](https://camo.githubusercontent.com/b18e114e8ffcc8709b19f5dc2bee54bc576aed17f4f579140d0a42d83d2cfd05/68747470733a2f2f706f7365722e707567782e6f72672f79616e6e6f66662f636f6d706f7365722d646f74656e762d68616e646c65722f6c6963656e7365)](https://packagist.org/packages/yannoff/composer-dotenv-handler)

Composer script to handle `.env` file maintenance, based upon the concept of the popular [incenteev/composer-parameter-handler](https://github.com/Incenteev/ParameterHandler) package.

Usage
-----

[](#usage)

First you must require the package:

```
$ composer require yannoff/composer-dotenv-handler
```

Then, set up your `composer.json` accordingly, as in the following example:

```
...
    "scripts": {
        "post-install-cmd": "Yannoff\\DotenvHandler\\ScriptHandler::updateEnvFile"
    }
...
```

Advanced options
----------------

[](#advanced-options)

Options may be passed via the `extra` section of the composer.json :

```
    "extra": {
        "yannoff-dotenv-handler": {
            // options here
        }
    }
```

### Available options

[](#available-options)

**Name****Default value****Description**file.envThe name of the auto-generated *dotenv* filedist-file.env.distThe name of the template file (the *dist* file)keep-outdatedtrueKeep values in the *env file* that are not anymore in the *dist file*behaviornormalIf set to **flex**, enable support for Symfony Flex applications (see [next section](#symfony-flex-behavior) for details)### Symfony Flex Behavior

[](#symfony-flex-behavior)

As of November 2018, the guys at Symfony decided to [change radically](https://symfony.com/doc/current/configuration/dot-env-changes.html) how `dotenv` files are handled in symfony applications.

A **local** *temporary workaround* could be to modify the `composer.json` extra section as follow:

```
    "extra": {
        "yannoff-dotenv-handler": {
            "file": ".env.local",
            "dist-file": ".env"
        }
    }
```

Anyway this is not an acceptable solution, indeed the *dotenv file name* may vary from one deploy environment to another (test, staging, prod...): the `composer.json` can't be committed as is.

*So here comes the behavior option:*

```
    "extra": {
        "yannoff-dotenv-handler": {
            "behavior": "flex"
        }
    }
```

When in **flex behavior mode**, the script will build the **dotenv file name** automatically, based upon either the `APP_ENV` or `ENV` (in this order of preference) environment variable (will use *local* as default value, if not set) at runtime.

*For example, issuing the following command in a terminal:*

```
$ /usr/bin/env ENV=staging composer install
```

*would result in having the following config values:*

- `dist-file` : `.env`
- `file` : `.env.staging`

Licence
-------

[](#licence)

Licensed under the [MIT Licence](LICENSE).

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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

Every ~96 days

Recently: every ~197 days

Total

11

Last Release

1677d ago

PHP version history (4 changes)1.0.0PHP &gt;=7.0

1.1.1PHP &gt;=7.1.3

1.1.4PHP ^5.5.9|&gt;=7.0.8

1.2.4PHP ^5.6|&gt;=7.0.8

### Community

Maintainers

![](https://www.gravatar.com/avatar/0f7d03ec2e1304f585bacac055f09969294b8c08146d6be1d00504193be3bc9e?d=identicon)[yannoff](/maintainers/yannoff)

---

Top Contributors

[![yannoff](https://avatars.githubusercontent.com/u/20049273?v=4)](https://github.com/yannoff "yannoff (16 commits)")

---

Tags

composercomposer-scriptsdotenvenvenvironment-variablescomposerenvdotenv

### Embed Badge

![Health badge](/badges/yannoff-composer-dotenv-handler/health.svg)

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

###  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.2k](/packages/symfony-dotenv)[helhum/dotenv-connector

Makes it possible to set environment variables for composer projects.

1594.6M34](/packages/helhum-dotenv-connector)[sroze/companienv

Companion for .env files

245418.8k1](/packages/sroze-companienv)[wecodemore/wpstarter

Composer plugin to easily build WordPress websites entirely managed via Composer.

253195.2k6](/packages/wecodemore-wpstarter)[ffraenz/private-composer-installer

A composer install helper for private packages

2331.7M5](/packages/ffraenz-private-composer-installer)

PHPackages © 2026

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