PHPackages                             mahbubhelal/sync-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. [Testing &amp; Quality](/categories/testing)
4. /
5. mahbubhelal/sync-env

ActiveLibrary[Testing &amp; Quality](/categories/testing)

mahbubhelal/sync-env
====================

A laravel package to sync env variables between different .env files.

1.0(4mo ago)013MITPHPPHP ^8.3

Since Dec 27Pushed 3mo agoCompare

[ Source](https://github.com/mahbubhelal/sync-env)[ Packagist](https://packagist.org/packages/mahbubhelal/sync-env)[ RSS](/packages/mahbubhelal-sync-env/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (8)Versions (2)Used By (0)

SyncEnv
=======

[](#syncenv)

A highly opinionated Laravel package to sync environment variables between different `.env` files and view differences between them. Ensures all your `.env` files are consistent, clean, and strictly follow best practices for key/value formatting.

Features
--------

[](#features)

- **Strict .env key rules:** Only allows keys that are upper snake case, starting with an uppercase letter and containing only uppercase letters, numbers, or underscores (minimum 2 characters).
- **No leading/trailing spaces:** No line in any `.env` file may have leading or trailing spaces. Values must not have leading or trailing spaces.
- **Identical structure:** The synced `.env` files will have the exact same structure, order, comments, and blank lines as `.env.example`, differing only in values where present.
- **Sync .env files:** Synchronize keys from `.env.example` to all other `.env*` files, preserving existing values and creating backups.
- **Show diffs:** View differences between `.env.example` and other `.env` files, including options to show all keys or include backup files.
- **Backup management:** Automatically create backups before syncing, and remove old backups with options.

Key Format Rules
----------------

[](#key-format-rules)

- Keys must be in **UPPER\_SNAKE\_CASE**.
- Keys must start with an uppercase letter (`A-Z`).
- Keys must be at least 2 characters long.
- Keys may only contain uppercase letters (`A-Z`), numbers (`0-9`), and underscores (`_`).
- No leading or trailing spaces are allowed in any line.
- Values must not have leading or trailing spaces.

### Examples

[](#examples)

**Valid keys:**

```
APP_NAME
DB_CONNECTION
FOO_BAR_123

```

**Invalid keys:**

```
app_name        # not uppercase
A               # single character not allowed
_DB_CONNECTION  # cannot start with underscore
 APP_NAME       # leading space
APP-NAME        # dash not allowed
APP NAME        # space not allowed
APP@NAME        # special char not allowed

```

**Invalid values:**

```
APP_NAME= MyApp     # leading space in value
APP_NAME=MyApp      # trailing space in value

```

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

[](#installation)

```
composer require mahbubhelal/sync-env
```

Usage
-----

[](#usage)

### 1. Sync .env files

[](#1-sync-env-files)

Synchronize `.env.example` to all other `.env*` files:

```
php artisan sync-env:example-to-envs
```

#### Options:

[](#options)

- `--no-backup` (`-N`): Do not create a backup of the target `.env` file before syncing.
- `--remove-backups` (`-r`): Remove previously created backup files before syncing.
- `-v` (verbose): Show detailed warnings about comment differences, key position differences, and additional keys in target files.

### 2. Show differences between .env files

[](#2-show-differences-between-env-files)

Display differences between `.env.example` and other `.env` files:

```
php artisan sync-env:show-diffs
```

#### Options:

[](#options-1)

- `--all` (`-a`): Show all keys, including identical ones.
- `--include-backup` (`-b`): Include backup files in the diff view.
- `--only=`: Only show specific env files (comma-separated, e.g., `--only=.env,.env.staging`).
- `--exclude=`: Exclude specific env files (comma-separated, e.g., `--exclude=.env.testing`).

Note: At least 2 env files are required. If `--only` or `--exclude` results in fewer than 2 files, `.env.example` is automatically included.

Example Workflow
----------------

[](#example-workflow)

1. Update your `.env.example` file with new keys or changes, following the strict key/value rules above.
2. Run the sync command to propagate changes to all `.env` files: ```
    php artisan sync-env:example-to-envs
    ```
3. Use the show-diffs command to review differences: ```
    php artisan sync-env:show-diffs
    ```

Testing
-------

[](#testing)

Run tests with Pest:

```
vendor/bin/pest
```

License
-------

[](#license)

MIT

---

**Author:** Md Mahbub Helal ()

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance76

Regular maintenance activity

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

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

Unknown

Total

1

Last Release

143d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7133d7d156fc25a67474a27228a17475407b62ed2308a6e51c8f3a35407fbada?d=identicon)[mahbub\_helal](/maintainers/mahbub_helal)

---

Top Contributors

[![mahbubhelal](https://avatars.githubusercontent.com/u/7233764?v=4)](https://github.com/mahbubhelal "mahbubhelal (19 commits)")

---

Tags

testinglaraveldevelopmentenvsync

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mahbubhelal-sync-env/health.svg)

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

###  Alternatives

[behat/behat

Scenario-oriented BDD framework for PHP

4.0k96.8M2.0k](/packages/behat-behat)[davestewart/sketchpad

An innovative front-end environment for interactive Laravel development

29512.9k1](/packages/davestewart-sketchpad)[guanguans/laravel-soar

SQL optimizer and rewriter for laravel. - laravel 的 SQL 优化器和重写器。

2227.8k](/packages/guanguans-laravel-soar)[hyvor/laravel-playwright

Laravel and Playwright E2E Testing

3312.0k](/packages/hyvor-laravel-playwright)[srlabs/laravel-testing-utilities

Helper utilities for testing Laravel Applications

1011.9k](/packages/srlabs-laravel-testing-utilities)

PHPackages © 2026

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