mirazmac/dotenvwriter
Mirazmac DotenvWriter is a PHP package for safely writing and updating .env files programmatically. Set, change, or delete environment variables while preserving comments and formatting—ideal for installers, admin panels, and CLI tools modifying Laravel or PHP app config.
Architecture fit
mirazmad/dotenvwriter is a single-purpose, framework-agnostic Composer library: it writes key/value pairs into a .env file. It is not a Laravel package (no service provider, facade, or config publish expected), which is actually an advantage — it adds no boot-time footprint, no auto-discovery surface, and no version coupling to the framework. In a Laravel architecture it belongs as a leaf dependency behind a thin internal adapter (e.g., App\Support\EnvWriter), never called directly from controllers or domain code. It fills a real gap: Laravel's read path (vlucas/phpdotenv via Dotenv\Dotenv) is read-only by design, so any write-back today is hand-rolled file_put_contents + regex, which is exactly the kind of code that quietly corrupts .env files.
The fit is strongest for installers, onboarding wizards, first-run setup commands, and CLI tooling — not for application runtime code paths.
Integration feasibility
Low effort. composer require mirazmac/dotenvwriter, one class instantiation, a handful of set/save calls. A TPM should budget this as a 1–2 day spike plus a 1-week hardening task (wrapper, tests, guardrails), not a multi-sprint integration. There is no schema, no migration, no external service, and no data model.
Technical risk
Dependency risk is low (MIT, zero-to-few transitive dependencies, small attack surface). Behavioral risk is medium-to-high because the library's job is to rewrite a file that the entire application's configuration depends on. The risks that matter are not "will it install" but "what does it do to the file":
export prefixes, quoted vs. unquoted values, escaped characters, multiline/JSON values, and CRLF line endings. Any of these regressing creates noisy diffs or silently changed values..env. Two workers writing simultaneously is an unguarded race.php artisan config:cache makes .env writes invisible to the running app. A "settings saved!" UI message that has no effect is a predictable support ticket.Key questions
rename) and does it lock?Stack fit
Clean. Composer-native, MIT, no framework assumptions — compatible with Laravel 10/11/12, Lumen, or plain PHP CLI scripts on PHP 8.1+. The natural integration points are:
app:configure or an installer step.config:cache is run.It should not be wired into request-handling code or any settings UI that implies durable runtime configuration.
Migration path
Most teams arrive here with ad-hoc preg_replace/file_put_contents code or a competing library (brotzka/dotenv-modifier, custom Symfony Dotenv extensions). Migration is mechanical:
.env write sites (grep for file_put_contents, fopen(..., 'w'), .env string literals)..env fixture and asserts byte-level or semantic equivalence.There is no data migration and no rollback complexity — the only artifact is a text file, which should be backed up before every write.
Compatibility
Two axes to verify during the spike: (a) PHP version support vs. the fleet's floor, and (b) formatting compatibility with the existing .env conventions in the repo (spacing around =, quoting style, comments). If the team's .env files diverge from what the library emits, every write produces a whole-file diff — which destroys code review and blame on that file. Pin the version in composer.json and treat upgrades as reviewed changes.
Sequencing
.env, confirm atomicity and formatting behavior.0600), environment guards, and structured logging.APP_ENV=production by default.Maintenance
The library itself is near-zero maintenance — small surface, stable problem domain, MIT fork rights if the maintainer disappears. The real maintenance cost is the internal adapter and its tests, which the team owns permanently. Budget a low but non-zero recurring cost: pinning, security advisories, and re-validating formatting behavior on upgrades. Treat it as "vendor with a fork escape hatch," not "vendor we depend on."
Support
Community-only, no SLA, 21 stars, single maintainer. Escalation path is "read the source and patch our fork." This is acceptable for a dev/ops-time utility and unacceptable for anything on a customer-facing critical path. Do not let it become load-bearing for production configuration.
Scaling
Poor fit for horizontal scale by design. Writing .env on one container or pod does not propagate to siblings; in ephemeral container environments the file is overwritten on every deploy anyway. The correct scaling story is: .env is immutable, injected configuration (secrets manager, parameter store, orchestrator env vars) is the source of truth, and this library is used only in single-instance provisioning and local setup. If a product requirement is "let admins change settings at runtime," the answer is a database-backed settings table with a config overlay — not a .env writer.
Failure modes
.env from a non-atomic write or interrupted process → total application outage on next boot. Mitigation: backup before write, atomic rename, health check on parse after write.config:cache → operators believe a change applied when it did not. Mitigation: force config:clear in the same command and report it..env → security incident. Mitigation: 0600, backup location outside the repo, .gitignore verified in CI.Ramp-up
Very low for engineers — the API is a few methods and the concept is familiar. The ramp-up cost sits with operators, not developers: the runbook must state when this is allowed (install/local only), what must follow a write (config cache clear, service reload), and how to recover (restore the backup). A TPM should ensure that runbook exists before the first production-adjacent use, and should position this package explicitly as a setup-time convenience utility, not a configuration management solution.
How can I help you explore Laravel packages today?