mahbubhelal/sync-env
Composer 安装命令:
composer require --dev mahbubhelal/sync-env
包简介
A laravel package to sync env variables between different .env files.
README 文档
README
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
- 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
.envfile may have leading or trailing spaces. Values must not have leading or trailing spaces. - Identical structure: The synced
.envfiles 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.exampleto all other.env*files, preserving existing values and creating backups. - Show diffs: View differences between
.env.exampleand other.envfiles, 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
- 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
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
composer require mahbubhelal/sync-env
Usage
1. Sync .env files
Synchronize .env.example to all other .env* files:
php artisan sync-env:example-to-envs
Options:
--no-backup(-N): Do not create a backup of the target.envfile 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
Display differences between .env.example and other .env files:
php artisan sync-env:show-diffs
Options:
--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
- Update your
.env.examplefile with new keys or changes, following the strict key/value rules above. - Run the sync command to propagate changes to all
.envfiles:php artisan sync-env:example-to-envs
- Use the show-diffs command to review differences:
php artisan sync-env:show-diffs
Testing
Run tests with Pest:
vendor/bin/pest
License
MIT
Author: Md Mahbub Helal (mdhelal00@gmail.com)
mahbubhelal/sync-env 适用场景与选型建议
mahbubhelal/sync-env 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 43 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「testing」 「sync」 「development」 「laravel」 「env」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mahbubhelal/sync-env 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mahbubhelal/sync-env 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mahbubhelal/sync-env 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Testing Suite For Lumen like Laravel does.
Debugging a problem and need to login as one of your customers? This allows you to authenticate as any of your customers.
A sleek PHP wrapper around rclone with Laravel-style fluent API syntax
Library with classes to help you do batch.
Sync content to other sites on element save.
The PHP SDK for Checkmango
统计信息
- 总下载量: 43
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-27