PHPackages                             dbtlr/php-env-builder - 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. [CLI &amp; Console](/categories/cli)
4. /
5. dbtlr/php-env-builder

ActiveLibrary[CLI &amp; Console](/categories/cli)

dbtlr/php-env-builder
=====================

A PHP library that assists in automating the building of .env files.

v1.0.0(7y ago)1182[1 issues](https://github.com/dbtlr/php-env-builder/issues)[1 PRs](https://github.com/dbtlr/php-env-builder/pulls)1MITPHPPHP ^7.1CI failing

Since Aug 15Pushed 5y agoCompare

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

READMEChangelog (3)Dependencies (7)Versions (4)Used By (1)

PHP Env Builder
===============

[](#php-env-builder)

[![Latest Version](https://camo.githubusercontent.com/c2bde24b083c5b77fbe0debcca1ed1fab9833d99fb341a01ec7f43c33d7a5b9a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672f6462746c722f7068702d656e762d6275696c6465722e7376673f7374796c653d666c6174266c6162656c3d72656c65617365)](https://github.com/dbtlr/php-env-builder/tags)[![Software License](https://camo.githubusercontent.com/f251623e510f5909f16ae3f4e6e548dac11340b9fde1a99be26b015b39272c00/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c6174)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/72714d5de8ad28f04c1f705c749c56893cf880e0c24f420523b6dc9989b45ef9/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6462746c722f7068702d656e762d6275696c6465722f6d61737465722e7376673f7374796c653d666c6174)](https://travis-ci.org/dbtlr/php-env-builder)[![Coverage Status](https://camo.githubusercontent.com/f1cdab16973ceb07183880fd38a9a8b9630e6fdf009efff414c177eaec59dc90/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6462746c722f7068702d656e762d6275696c6465722e7376673f7374796c653d666c6174)](https://scrutinizer-ci.com/g/dbtlr/php-env-builder/code-structure)[![Quality Score](https://camo.githubusercontent.com/658f5f34daf540b44cbd5c2918ed8e9dbc6ff51d3980af9735ed2b08fdc7345f/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6462746c722f7068702d656e762d6275696c6465722e7376673f7374796c653d666c6174)](https://scrutinizer-ci.com/g/dbtlr/php-env-builder)[![Total Downloads](https://camo.githubusercontent.com/f485d191053ca15cc22fdb69d3e57d7b2acd72a004a6c674a38b69c3f4f5a4ef/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6462746c722f7068702d656e762d6275696c6465722e7376673f7374796c653d666c6174)](https://packagist.org/packages/dbtlr/php-env-builder)

Makes building .env files from the command-line simple.

For loading and using .env files in your development workflow, I highly suggest looking to the [vlucas/phpdotenv](https://github.com/vlucas/phpdotenv) package, which helps abstract out the process of loading environmental variables. This library is designed to help you build a local .env library that you can add to your .gitignore file, without the extra .env.example file that most people add to document how to build it.

[Why .env?](https://github.com/vlucas/phpdotenv#why-env)

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

[](#installation)

The recommended method of installing this library is via [Composer](https://getcomposer.org/).

Run the following command from your project root:

```
$ composer require --dev dbtlr/php-env-builder
```

Usage as a Composer Script
--------------------------

[](#usage-as-a-composer-script)

Because Composer provides its own way of working with the console IO, the `extra.php-env-builder` config is the proper way of setting up your questions and variable names in this use case.

In order to have your .env file built when you run `composer install` or `composer update` you should provide config similar to this:

```
{
    "scripts": {
        "build-env": "Dbtlr\\PHPEnvBuilder\\ComposerScriptRunner::build",
        "post-install-cmd": "@build-env",
        "post-update-cmd": "@build-env"
    },
    "extra": {
        "php-env-builder": {
            "envFile": ".env",
            "questions": [
                {
                    "name": "MYSQL_HOST",
                    "prompt": "What is the hostname for the MySQL server?",
                    "default": "127.0.0.1",
                    "required": true
                },
                {
                    "name": "MYSQL_PORT",
                    "prompt": "The port for the MySQL server?",
                    "default": "3306",
                    "required": true
                },
                {
                    "name": "MYSQL_USER",
                    "prompt": "What is the MySQL user?",
                    "default": "app",
                    "required": true
                },
                {
                    "name": "MYSQL_PASSWORD",
                    "prompt": "What is the MySQL password?",
                    "default": "app-password",
                    "required": true
                }
            ]
        }
    }
}
```

### All `extra.php-env-builder` options

[](#all-extraphp-env-builder-options)

- questions - default: \[\] `(required)` // An array of questions that contain at least the `name` and `prompt` elements.
- envFile - default: `.env` // Either the absolute location or one that is relative to your `package.json` file.
- clobber - default: `false` // Will an existing .env file be overwritten on build?
- loadEnv - default: `false` // If an existing file is being clobbered, will it be loaded to provide defaults?
- verbose - default: `false` // Extra output

General Usage
-------------

[](#general-usage)

If you would like to roll your own script, the syntax itself is fairly straightforward.

Note: This is a less expected use case, since the console IO needs to be provided by Composer, in order for it to accept input from inside a Composer script. This may be useful if you want to run this instead from a Makefile or an `npm run postinstall`

```
require_once __DIR__ . "/vendor/autoload.php";

$config = [
    'verbose' => true,
    'loadEnv' => true,
];

$builder = new \Dbtlr\PHPEnvBuilder\Builder('/path/to/.env', $config);

$builder->ask(
    'name',              // ENV variable name
    'What is your name?' // Command prompt
    '',                  // Default answer
    true                 // Is required?
);

$builder->run(); // Run the builder and return the answers.
$builder->write(); // Write the answers to the file.
```

Running tests?
--------------

[](#running-tests)

All tests are run using PHPUnit. Make sure you have at least PHP 7.1 installed, as well as [Composer](https://getcomposer.org).

To run tests, simply run:

```
composer install
composer test
```

Want to contribute?
-------------------

[](#want-to-contribute)

[Read more here](https://github.com/dbtlr/php-env-builder/blob/master/CONTRIBUTING.md)

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity59

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

Every ~0 days

Total

3

Last Release

2828d ago

Major Versions

0.5 → v1.0.02018-08-17

PHP version history (2 changes)0.0.1PHP ^5.6|^7.0

0.5PHP ^7.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/195095?v=4)[Drew Butler](/maintainers/dbtlr)[@dbtlr](https://github.com/dbtlr)

---

Top Contributors

[![dbtlr](https://avatars.githubusercontent.com/u/195095?v=4)](https://github.com/dbtlr "dbtlr (30 commits)")

---

Tags

phpcliterminalbuilderenvcommand

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/dbtlr-php-env-builder/health.svg)

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

###  Alternatives

[league/climate

PHP's best friend for the terminal. CLImate allows you to easily output colored text, special formats, and more.

1.9k14.0M273](/packages/league-climate)[phalcon/cli-options-parser

Command line arguments/options parser.

181.0M7](/packages/phalcon-cli-options-parser)[php-school/learn-you-php

An introduction to PHP's core features: i/o, http, arrays, exceptions and so on.

3192.0k](/packages/php-school-learn-you-php)

PHPackages © 2026

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