syamsoul/laravel-set-env
Programmatically set, update, and read Laravel .env variables with a simple facade and CLI. Supports comments, precise placement, and multiple env files (.env, .env.example). Includes production safety checks for secure environment configuration management.
.env variables without manual file edits, reducing deployment friction for feature flags, environment-specific settings, or A/B testing configurations..env variables differ per tenant/environment (e.g., database URLs, API keys). Reduces duplication with templated .env files..env variables, reducing code complexity..env files by enabling programmatic validation and updates (e.g., enforcing variable formats via comments)..env updates (e.g., daily feature rollouts, environment-specific overrides)..env configuration during deployments (e.g., Kubernetes secrets, Terraform outputs)..env.example, .env.staging, .env.prod with shared or templated variables..env changes (e.g., comments for variable purposes, positional control to avoid sensitive data exposure)..env Management: Migrating from manual .env edits or outdated packages (e.g., vlucas/phpdotenv) to a Laravel-first solution.vlucas/phpdotenv or phpdotenv/phpdotenv..env variables are rarely updated (manual edits suffice)..env files (e.g., sealed containers); use runtime secrets managers (e.g., AWS Secrets Manager, HashiCorp Vault) instead.spatie/laravel-env-editor..env files (e.g., laravel/env-editor with Git integration).*"This package lets us automate environment configurations—cutting deployment time by ~[X]% and reducing errors from manual .env edits. For example:
TENANT_DB_URL) during onboarding..env files from pipeline variables..env variables for audit trails (e.g., DB_TIMEOUT=30 # Set by security policy).
Cost: Minimal (~$0 for open-source). ROI: Faster releases, fewer config-related incidents."**"Why this package over alternatives? ✅ Laravel-Native: Uses facades and Artisan commands—no reinventing the wheel. ✅ Safety First:
DEBUG=true # Enable for staging only).API_KEY after APP_NAME).
✅ CLI + Code: Update .env via php artisan or PHP code (e.g., Env::set('LOG_LEVEL', 'debug')).
✅ Production-Ready: --force flag for scripts, no prompts in automated workflows.Use Cases to Target:
FEATURE_NEW_CHECKOUT=true via CLI during deployments..env.example with .env during git pull (avoid drift).QUEUE_CONNECTION=sync during outages.Risks:
.env files are writable by the web server (e.g., chmod 644 .env).php artisan souldoit:set-env --env_file=.env.staging).Next Steps:
.env management (manual edits? scripts?).composer.json and document CLI commands for the team."**"How This Fits Our Pipeline:
.env from Terraform outputs or Kubernetes secrets:
php artisan souldoit:set-env "DB_HOST=${DB_HOST}" --env_file=.env.prod
.env changes with:
git diff .env # Compare against Git for drift
.env changes via Git or package’s undo functionality.Tooling Integration:
.env from secrets.php artisan as a task to configure environments..env changes via Git hooks or Laravel events (e.g., Env::updated())."*How can I help you explore Laravel packages today?