PHPackages                             andriichuk/keepenv - 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. andriichuk/keepenv

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

andriichuk/keepenv
==================

KeepEnv is a tool for checking and managing environment variables based on a specification file.

0.3.0(4y ago)216[1 PRs](https://github.com/andriichuk/keepenv/pulls)MITPHPPHP ^7.4 || ^8.0

Since Jan 26Pushed 3y ago1 watchersCompare

[ Source](https://github.com/andriichuk/keepenv)[ Packagist](https://packagist.org/packages/andriichuk/keepenv)[ Docs](https://github.com/andriichuk/keepenv)[ RSS](/packages/andriichuk-keepenv/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (10)Versions (6)Used By (0)

🗒 KeepEnv
=========

[](#-keepenv)

[![SWUbanner](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg)](https://vshymanskyy.github.io/StandWithUkraine/)

Track Your Environment Variable Changes Using Specification
-----------------------------------------------------------

[](#track-your-environment-variable-changes-using-specification)

 [![Logo](https://github.com/andriichuk/keepenv/raw/main/art/logo.jpeg)](https://github.com/andriichuk/keepenv/blob/main/art/logo.jpeg)

 [ ![License: MIT](https://camo.githubusercontent.com/1402990fc2efe5e78b2723a502ac0d53ab9f0300ed9adb820cdeed17944e9299/68747470733a2f2f706f7365722e707567782e6f72672f616e647269696368756b2f6b656570656e762f6c6963656e73653f666f726d61743d666c6174) ](https://github.com/andriichuk/keepenv/blob/master/LICENSE) [ ![Tests](https://github.com/andriichuk/keepenv/actions/workflows/test.yml/badge.svg) ](https://github.com/andriichuk/keepenv/actions) [ ![Code coverage](https://camo.githubusercontent.com/f9e470bd048dc8bc6dade84b61dec106f7976411f7ff6b4261a766fea207d5e1/68747470733a2f2f636f6465636f762e696f2f67682f616e647269696368756b2f6b656570656e762f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d30374652315739585645) ](https://codecov.io/gh/andriichuk/keepenv) [ ![Psalm type coverage](https://camo.githubusercontent.com/46ff85681a294764f532ac762189f9b325a5b8272d7654d3fed74c8ebe9c172d/68747470733a2f2f73686570686572642e6465762f6769746875622f616e647269696368756b2f6b656570656e762f636f7665726167652e737667) ](https://github.com/andriichuk/keepenv/blob/main/psalm.xml) [ ![Psalm level](https://camo.githubusercontent.com/edfde4b6ca27aa4c38adfb91ca578ed501c857ac21ec815daec0270d213270ad/68747470733a2f2f73686570686572642e6465762f6769746875622f616e647269696368756b2f6b656570656e762f6c6576656c2e737667) ](https://github.com/andriichuk/keepenv/blob/main/psalm.xml) [ ![Stars](https://camo.githubusercontent.com/b53e30846e71d83906ddfd23d4c73d11851cb542aa7aa2a33f392a2a3fa6f9aa/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f616e647269696368756b2f6b656570656e763f636f6c6f723d626c7565) ](https://github.com/andriichuk/keepenv) [ ![Quality Gate Status](https://camo.githubusercontent.com/9bec0fae7cd1e6390d36e129d1244456bd35d8b6330ac962c7021c3c55762613/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d616e647269696368756b5f6b656570656e76266d65747269633d616c6572745f737461747573) ](https://sonarcloud.io/summary/new_code?id=andriichuk_keepenv)

[](#----------------------------------------------------------)

### Table Of Contents

[](#table-of-contents)

- [About](#about)
- [Installation](#installation)
- [Initialization](#initialization)
- [Validation](#validation)
- [Filling](#filling)
- [Adding](#adding)
- [Dumping](#dumping)
- [Syntax](#syntax)
- [Tips](#tips)
- [Contributing](#contributing)

### About

[](#about)

KeepEnv is a CLI tool for checking and managing environment variables based on a specification file.

Motivations:

- I want to have a way to describe all environment variables in one specification file.
- I want to make sure that all required variables are filled in correctly before deploying the application.
- I don't want to check variables in runtime.
- I want to keep track of new environment variables when they are added by one of my colleagues.
- I want to have a convenient and safe way to fill in new variables.
- I want to check variables from different state providers (system $\_ENV, from .env file + system or only from .env file).
- I don't want to manually describe all 100+ existing environment variables.
- I want to use a tool that will not be tied to a specific framework, because I work with several frameworks.

Features:

- Environment specification generation based on current `.env` files.
- Environment variables validation.
- Split variable definition between environments.
- Extend variables from particular environment e.g. `local` from `common`.
- Split system (`$_ENV`) and regular variables from `.env` files.
- Ability to fill missing variables through console command.

Supported dotenv file state loaders:

- [vlucas/phpdotenv](https://packagist.org/packages/vlucas/phpdotenv)
- [symfony/dotenv](https://packagist.org/packages/symfony/dotenv)
- [josegonzalez/dotenv](https://packagist.org/packages/josegonzalez/dotenv)

### Installation

[](#installation)

Install composer package:

```
composer require andriichuk/keepenv
```

### Initialization

[](#initialization)

This command allows you to generate a new environment specification file based on your current `.env` structure.

Basic usage:

```
./vendor/bin/keepenv init
```

This will create a specification file (`keepenv.yaml`) in your root directory with `common` environment.

Using preset (available presets: `laravel`, `symfony`):

```
./vendor/bin/keepenv init --preset=laravel
```

For Laravel Sail:

```
./vendor/bin/sail php ./vendor/bin/keepenv init --preset=laravel
```

Using custom `.env` files for `vlucas/dotenv` (paths to the folders with `.env` file):

```
./vendor/bin/keepenv init --env-file=./ --env-file=./config/
```

Using custom `.env` files for `symfony/dotenv` (direct file paths):

```
./vendor/bin/keepenv init --env-file=./.env --env-file=./.env.local
```

Environment file reader will be detected automatically, but you can customize it:

```
./vendor/bin/keepenv init --env-reader=symfony/dotenv --env-file=./.env
```

### Validation

[](#validation)

Using this command you can check your environment variables according to the specification file `keepenv.yaml`.

Basic usage:

```
./vendor/bin/keepenv validate common
```

Check only system variables (`$_ENV`) without looking at the `.env` file:

```
./vendor/bin/keepenv validate common --env-provider=system
```

Use `--help` option to check other parameters.

### Filling

[](#filling)

This command allows you to fill in and validate missing variable values from your `.env` file (use `--help` for list of all options).

Command:

```
./vendor/bin/keepenv fill
```

For specific environment:

```
./vendor/bin/keepenv fill --env=common
```

### Adding

[](#adding)

The following command can help you to add a new variable definition to specification and dotenv files:

```
./vendor/bin/keepenv add
```

### Dumping

[](#dumping)

Using this command you can export all your variables defined in `keepenv.yaml` file into the custom `.env` file.

Create a new `.env` file according to variables defined in the `keepenv.yaml` (same as `cp .env.example .env`). Variables will be filled in only with default values. Perhaps now you can delete the `.env.example` file:

```
./vendor/bin/keepenv dump
```

Dump system variables into the file:

```
./vendor/bin/keepenv dump --target-env-file=./.env.system --env-provider=system --with-values=true
```

Create a new `.env.stage` file based on `production` environment specification and current `.env` file:

```
./vendor/bin/keepenv dump --env=production --target-env-file=./.env.stage --env-file=./ --with-values=true
```

### Syntax

[](#syntax)

Currently, only the YAML syntax format is supported.

Environments definition:

```
version: '1.0'
environments:
    common:
        variables:
        # ...
    local:
        extends: common
        variables:
        # ...
    testing:
        variables:
        # ...
```

Variables definition:

- Describe the purpose of variables:

```
SESSION_LIFETIME:
    description: 'Session lifetime in minutes.'
```

- Mark that variable should be followed by `export` keyword in `.env` file (`export APP_LOCALE=en`):

```
APP_LOCALE:
    export: true
```

- Mark that variable should be set on the server-side (`$_ENV` or `$_SERVER`) not from `.env` file:

```
APP_TIMEZONE:
    system: true
```

- Specify default value (please use this only for non-sensitive data):

```
REDIS_PORT:
    default: 6379
```

- Describe validation rules:
    - Mark variable as required:

    ```
    APP_ENV:
        rules:
            required: true
    ```

    - Check that variable value is a string (can usually be omitted because all values in the `.env` file are read as strings by default):

    ```
    APP_ENV:
        rules:
            string: true
    ```

    - String with length range

    ```
    APP_KEY:
        rules:
            string:
                min: 32
                max: 60
    ```

    - Numeric

    ```
    REDIS_PORT:
        rules:
            numeric: true
    ```

    - Boolean (true/false, on/off, yes/no, 1/0)

    ```
    APP_DEBUG:
        rules:
            boolean: true
    ```

    - Boolean with custom options

    ```
    PAYMENT_FEATURE:
        rules:
            boolean:
                'true': Y
                'false': N
    ```

    - Email address

    ```
    MAIL_FROM_ADDRESS:
        rules:
            email: true
    ```

    - Enumeration:

    ```
    APP_ENV:
        rules:
            enum:
                - local
                - production
    ```

    - Means that the value of the variable must be equal (`==`) to a specific value.

    ```
    APP_ENV:
        rules:
            equals: local
    ```

    - IP address

    ```
    DB_HOST:
        rules:
            ip: true
    ```

Full example:

```
version: '1.0'
environments:
    common:
        variables:
            APP_NAME:
                description: 'Application name.'
            APP_ENV:
                description: 'Application environment name.'
                default: local
                rules:
                    required: true
                    enum:
                        - local
                        - production
            APP_DEBUG:
                rules:
                    boolean: true
            DB_HOST:
                description: 'Database host.'
                default: 127.0.0.1
                rules:
                    required: true
                    ip: true
            DB_PORT:
                description: 'Database port.'
                default: 3306
                rules:
                    required: true
                    numeric: true

    local:
        extends: common
        variables:
            APP_ENV:
                rules:
                    equals: local

    testing:
        variables:
            DB_DATABASE:
                description: 'Database name.'
                default: testing
                rules:
                    required: true
            DB_USERNAME:
                description: 'Database username.'
                rules:
                    required: true
            DB_PASSWORD:
                description: 'Database password.'
                rules:
                    required: true
```

### Tips

[](#tips)

Use `equals` rule to check for a specific value for the environment, e.g., a useful example for `APP_ENV`:

```
version: '1.0'
environments:
    common:
        variables:
            APP_ENV:
                rules:
                    required: true
                    enum:
                        - local
                        - production
            # ...
    production:
        extends: common
        variables:
            APP_ENV:
                rules:
                    equals: production
```

You can add a composer script for the new environment variables filling and validation:

```
"scripts": {
    "keepenv": "./vendor/bin/keepenv fill && ./vendor/bin/keepenv validate",
},
```

Then use:

```
composer keepenv common
```

You can also define `keepenv` common on `post-update-cmd` composer event, so environment filling and validation will be running after each `composer update`:

```
"scripts": {
    "post-update-cmd": [
        "@keepenv common"
    ]
},
```

### Contributing

[](#contributing)

Contributions, issues and feature requests are welcome.
Feel free to check [issues page](https://github.com/andriichuk/keepenv/issues) if you want to contribute. [Check the contributing guide](https://github.com/andriichuk/keepenv/blob/main/CONTRIBUTING.md).

### Credits

[](#credits)

- [Serhii Andriichuk](https://github.com/andriichuk)
- [All Contributors](https://github.com/andriichuk/keepenv/graphs/contributors)

### License

[](#license)

Copyright © 2022 [Serhii Andriichuk](https://github.com/andriichuk).
This project is [MIT](https://github.com/andriichuk/keepenv/blob/main/LICENSE) licensed.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

Total

4

Last Release

1554d ago

PHP version history (2 changes)0.1.0PHP ^7.4|^8.0

0.2.0PHP ^7.4 || ^8.0

### Community

Maintainers

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

---

Top Contributors

[![andriichuk](https://avatars.githubusercontent.com/u/38154251?v=4)](https://github.com/andriichuk "andriichuk (150 commits)")

---

Tags

configenvenv-specenv-validationenvironment-variablesphpenvdotenvenv-managerenv-specenv-validation

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/andriichuk-keepenv/health.svg)

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

###  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)[sroze/companienv

Companion for .env files

245418.8k1](/packages/sroze-companienv)[helhum/dotenv-connector

Makes it possible to set environment variables for composer projects.

1594.6M33](/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)[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)
