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

ActiveComposer-plugin[Utility &amp; Helpers](/categories/utility)

charlretief/build-env
=====================

Composer plugin to build .env files from .env.example with advanced configuration management

2.5(4y ago)01.4k1[1 PRs](https://github.com/charlretief/build-env/pulls)GPL-3.0PHP

Since Apr 14Pushed 4y agoCompare

[ Source](https://github.com/charlretief/build-env)[ Packagist](https://packagist.org/packages/charlretief/build-env)[ RSS](/packages/charlretief-build-env/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (8)Dependencies (3)Versions (9)Used By (0)

composer build-env
==================

[](#composer-build-env)

Build .env files from .env.example with advanced configuration management for different project environments like local, testing, staging, production. Also supports dynamic variables and environment defaults in ENV values.

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

[](#installation)

Using composer:

```
composer global require "charlretief/build-env":"^2"

```

Usage
-----

[](#usage)

```
composer build-env [] [] [--set-defaults] [--setup]

```

### Multi-environment Build Setup

[](#multi-environment-build-setup)

To setup a project for multi-environment builds run:

```
composer build-env --setup

```

After running the setup new sections will be added to the .env.example like:

```
################################################################
# APP_ENV=production
################################################################
#APP_DEBUG=false
#APP_ENV=production

```

Variables put under these sections will be used when the target build environment matches the name in APP\_ENV comment section. Values in this section should be commented, they will get uncommented when the target build environment matches.

### Basic Usage

[](#basic-usage)

To build a basic .env file for local development just run:

```
composer build-env

```

or to specify a different build environment:

```
composer build-env staging

```

### Advanced Usage #1 - Pinned values

[](#advanced-usage-1---pinned-values)

Pinned values allows for local overrides to values that should not be replaced by running build-env. One possible use for this is secrets management like database credentials that you do not want to commit into vcs.

To create local pinned values simply add them to the bottom of any generated .env file below the placeholder.

```
################################################################
# Local pinned values                                          #
################################################################
DB_USERNAME="root"
DB_PASSWORD="password123"

```

After adding pinned values run `composer build-env` again. It will then comment out the same variables in the generated portion of the file to prevent duplicate keys in the file.

### Advanced Usage #2 - Defaults file

[](#advanced-usage-2---defaults-file)

A defaults file is another "env" file, that allows for overwriting keys in the .env.example with default values.

This is useful for CI/CD processes that need to always set the same hostnames in all .env files. It can also function as an alternative to pinned values for secrets management for things like database credentials that you do not want to commit into vcs.

For example to always overwriting your DB\_HOST create a file `.env.defaults` (can be any filename) with content:

```
DB_HOST="127.0.0.1"

```

Then the generated .env file will always have this value for DB\_HOST.

```
composer build-env local .env.defaults

```

To remember your defaults file for next time you run without the defaults option add the --set-defaults argument:

```
composer build-env local .env.defaults --set-defaults

```

### Advanced Usage #3 - Placeholder variable substitution

[](#advanced-usage-3---placeholder-variable-substitution)

In the .env.example file there can be placeholder variables in double curly braces, like `{{myvar}}`, that will be replaced with values from a defaults file if they are present in the defaults file.

Example:

```
CONTACT_EMAIL={{EMAIL}}
APP_URL="http://{{myvar}}.local.dev"

```

Version 2
---------

[](#version-2)

[build-env version 1](readme_v1.md) is now deprecated, and with it the experimental .env.json file format. However version 2 will remain fully backwards compatible with reading the .env.json file format.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

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 ~113 days

Recently: every ~27 days

Total

8

Last Release

1789d ago

Major Versions

1.1 → 2.02021-02-16

### Community

Maintainers

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

---

Top Contributors

[![charlretief](https://avatars.githubusercontent.com/u/40823712?v=4)](https://github.com/charlretief "charlretief (14 commits)")

### Embed Badge

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

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

###  Alternatives

[akaunting/laravel-money

Currency formatting and conversion package for Laravel

7825.3M18](/packages/akaunting-laravel-money)[mglaman/composer-drupal-lenient

1317.4M15](/packages/mglaman-composer-drupal-lenient)[lullabot/drainpipe

An automated build tool to allow projects to have a set standardized operations scripts.

41716.4k2](/packages/lullabot-drainpipe)[drupal/core-project-message

Adds a message after Composer installation.

2122.6M172](/packages/drupal-core-project-message)[olvlvl/composer-attribute-collector

A convenient and near zero-cost way to retrieve targets of PHP 8 attributes

184108.8k8](/packages/olvlvl-composer-attribute-collector)[vaimo/composer-changelogs

Provide information about package changes based on changelog files that are bundled with releases; provide tools for generating documentation files from changelog sources

11150.5k10](/packages/vaimo-composer-changelogs)

PHPackages © 2026

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