PHPackages                             vsouz4/companienv - 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. vsouz4/companienv

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

vsouz4/companienv
=================

Companion for .env files

0.0.12(6y ago)08MITPHPPHP &gt;=7.0

Since Jan 29Pushed 6y ago1 watchersCompare

[ Source](https://github.com/vsouz4/companienv)[ Packagist](https://packagist.org/packages/vsouz4/companienv)[ RSS](/packages/vsouz4-companienv/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (7)Versions (13)Used By (0)

Companienv
==========

[](#companienv)

Your companion for `.env` files. Everybody knows about [12 factor](https://12factor.net/) and [environments variables](https://12factor.net/config) now. A lot of frameworks such as Symfony [are using a `.env` file](https://symfony.com/doc/current/configuration.html#the-env-file-environment-variables) to configure the application, but we don't have anything to help users to complete their local `.env` file.

Companienv will helps you manage the `.env` files, from a reference `.env.dist` version in your code repository. Companienv can:

- Read and populate default values
- Identify and ask only missing variables
- Ask variables [only if matching some conditions](#only-if-extension)
- [Propagate files](#file-to-propagate-extension) (copy files from somewhere else)
- Generate [public/private RSA keys](#rsa-pair-extension)
- Generate [SSL certificates](#ssl-certificate-extension)
- Much more, via [your own extensions](#your-own-extensions)

Usage
-----

[](#usage)

1. Require `sroze/companienv` as your project dependency:

```
composer req sroze/companienv

```

2. Run your companion:

```
vendor/bin/companienv

```

### Composer automation

[](#composer-automation)

You can run Companienv automatically after `composer install` or `composer update` commands by configuring the scripts in your `composer.json` file:

```
{
    "scripts": {
        "post-install-cmd": [
            "Companienv\\Composer\\ScriptHandler::run"
        ],
        "post-update-cmd": [
            "Companienv\\Composer\\ScriptHandler::run"
        ]
    }
}
```

By default, the file used as a template is `.env.dist` and the written file is `.env`. You can change these defaults within your `composer.json` file:

```
{
    "extra": {
        "companienv-parameters": [
            {
                "file": ".env.foo",
                "dist-file": ".env.foo.dist"
            }
        ]
    }
}
```

The `.env.dist` file
--------------------

[](#the-envdist-file)

**All your configuration is directly in your `.env.dist` file, as comments.** The configuration is divided in blocks that will be displayed to the user for a greater understanding of the configuration. Here are the fondations for Companienv:

- **Blocks.** They logically group variables together. They are defined by a title (line starting with a double-comment `##`) and a description (every comment line directly bellow)
- **Attributes.** Defined by a line starting with `#+`, an attribute is associated to one or multiple variables. These attributes are the entrypoint for extensions. In the example above, it says that the `JWT_*` variables are associated with an RSA key pair, so Companienv will automatically offer the user to generate one for them.
- **Comments.** Lines starting by `#~` will be ignored by Companienv.

*Example of `.env.dist.` file*

```
# .env.dist

## Welcome in the configuration of [my-project]
#
#~ Please run the `bin/start` command.
#~ These lines starting with `~` are not going to be displayed to the user

## GitHub
# In order to be able to login with GitHub, you need to create a GitHub application. To get access to the code
# repositories, you need to create a GitHub integration.
#
#+file-to-propagate(GITHUB_INTEGRATION_KEY_PATH)
#
GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=
GITHUB_INTEGRATION_ID=
GITHUB_INTEGRATION_KEY_PATH=
GITHUB_SECRET=

## Security
# We need sauce! Well, no, we need an SSL certificate.
#
#+rsa-pair(JWT_PRIVATE_KEY_PATH JWT_PUBLIC_KEY_PATH JWT_PRIVATE_KEY_PASS_PHRASE)
#
JWT_PRIVATE_KEY_PATH=/runtime/keys/jwt-private.pem
JWT_PUBLIC_KEY_PATH=/runtime/keys/jwt-public.pem
JWT_PRIVATE_KEY_PASS_PHRASE=

## Another block
# With its (optional) description
AND_OTHER_VARIABLES=

```

Built-in extensions
-------------------

[](#built-in-extensions)

- [Only if ...](#only-if-extension)
- [Propagate file](#file-to-propagate-extension)
- [RSA keys](#rsa-pair-extension)
- [SSL certificate](#ssl-certificate-extension)

### `only-if` extension

[](#only-if-extension)

Some of the blocks of your `.env` file might not even be relevant if some other variable was disabling a given feature.

**Example:** This will only ask for the `INTERCOM_APPLICATION_ID` variable if `INTERCOM_ENABLED` has the value (current or entered by the user) `true`.

```
## Support & Feedback
# If you would like to allow your users to get some support from you, give you some feedback and this
# sort of things, select the integrations you'd like.
#
#+only-if(INTERCOM_APPLICATION_ID):(INTERCOM_ENABLED=true)
#
INTERCOM_ENABLED=false
INTERCOM_APPLICATION_ID=none

```

### `file-to-propagate` extension

[](#file-to-propagate-extension)

Will ask the path of an existing file and copy it to the destination mentioned in the reference.

**Example:** this will ask the user to give the path of an existing file. It will copy this file to the path `/runtime/keys/firebase.json`, relative to the root directory of the project.

```
#+file-to-propagate(FIREBASE_SERVICE_ACCOUNT_PATH)
FIREBASE_SERVICE_ACCOUNT_PATH=/runtime/keys/firebase.json
```

### `rsa-pair` extension

[](#rsa-pair-extension)

If the public/private key pair does not exist, Companienv will offer to generate one for the user.

```
#+rsa-pair(JWT_PRIVATE_KEY_PATH JWT_PUBLIC_KEY_PATH JWT_PRIVATE_KEY_PASS_PHRASE)
JWT_PRIVATE_KEY_PATH=/runtime/keys/jwt-private.pem
JWT_PUBLIC_KEY_PATH=/runtime/keys/jwt-public.pem
JWT_PRIVATE_KEY_PASS_PHRASE=
```

### `ssl-certificate-extension`

[](#ssl-certificate-extension)

Similar to the [RSA keys pair](#rsa-pair-extension): Companienv will offer to generate a self-signed SSL certificate if it does not exist yet.

```
#+ssl-certificate(SSL_CERTIFICATE_PRIVATE_KEY_PATH SSL_CERTIFICATE_CERTIFICATE_PATH SSL_CERTIFICATE_DOMAIN_NAME)
SSL_CERTIFICATE_PRIVATE_KEY_PATH=/runtime/keys/server.key
SSL_CERTIFICATE_CERTIFICATE_PATH=/runtime/keys/server.crt
SSL_CERTIFICATE_DOMAIN_NAME=
```

Your own extensions
-------------------

[](#your-own-extensions)

You can easily create and use your own extensions with Companienv. In order to do so, you'll have to start Companienv with your own PHP file and use the `registerExtension` method of the `Application`:

```
use Companienv\Application;
use Companienv\Extension;

$application = new Application($rootDirectory);
$application->registerExtension(new class() implements Extension {
    // Implements the interface...
});
$application->run();
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 89.1% 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 ~73 days

Recently: every ~197 days

Total

12

Last Release

2214d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16051418?v=4)[Vitor de Souza](/maintainers/vsouz4)[@vsouz4](https://github.com/vsouz4)

---

Top Contributors

[![sroze](https://avatars.githubusercontent.com/u/804625?v=4)](https://github.com/sroze "sroze (41 commits)")[![vsouz4](https://avatars.githubusercontent.com/u/16051418?v=4)](https://github.com/vsouz4 "vsouz4 (3 commits)")[![carusogabriel](https://avatars.githubusercontent.com/u/16328050?v=4)](https://github.com/carusogabriel "carusogabriel (1 commits)")[![elodieirdor](https://avatars.githubusercontent.com/u/1608447?v=4)](https://github.com/elodieirdor "elodieirdor (1 commits)")

---

Tags

configurationenvdotenv

###  Code Quality

TestsBehat

### Embed Badge

![Health badge](/badges/vsouz4-companienv/health.svg)

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

###  Alternatives

[vlucas/phpdotenv

Loads environment variables from `.env` to `getenv()`, `$\_ENV` and `$\_SERVER` automagically.

13.5k602.4M5.4k](/packages/vlucas-phpdotenv)[sroze/companienv

Companion for .env files

245418.8k1](/packages/sroze-companienv)[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)[josegonzalez/dotenv

dotenv file parsing for PHP

2799.8M137](/packages/josegonzalez-dotenv)[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)

PHPackages © 2026

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