Vanni7544's avatar

Vanni7544 started a new conversation+100 XP

3mos ago

Manage .env files in Laravel (export, validate, backup, rollback)

Over the last few weeks, I’ve been working on a small tool for Laravel that was born from a real-world problem I kept running into: safely managing .env files across multiple environments (local, staging, production).

I noticed how little it takes — a missing value, a wrong variable, a rushed copy-paste — to break an application. And when this happens in production, it’s stressful and risky.

So I decided to build something that would make .env management a bit safer and more controlled — without changing how Laravel works.

I’m sharing it because it might be useful to others, and also because I’d love to hear how you all manage this topic in your own workflows.


🔐 What the tool does (in simple terms)

The .env file usually contains things like:

• database credentials
• API keys
• environment mode
• other critical configuration values

It’s a fragile file — one wrong line and the app stops working.

So the tool acts like a “safety layer” for .env.

It lets you:

✔ manage configuration per-environment
✔ export a generated .env when you choose
✔ automatically back up your current .env
✔ roll back instantly if needed

And most importantly:

➡ your real .env is NOT touched unless you explicitly apply it


🧪 Examples

Export a configuration:

php artisan config-manager:export <project-id> <environment-id>

This creates:

.env.config-manager

Your .env is not modified yet.

Apply the configuration (with automatic backup):

php artisan config-manager:export <project-id> <environment-id> --apply

This will:

✔ back up your current .env into .env.backups/
✔ replace it with the generated one

Rollback to the previous .env:

php artisan config-manager:export --rollback

Instant restore — no drama 🙂

If the environment is marked as production, the tool also shows a clear confirmation prompt before doing anything — so you don’t accidentally overwrite live configuration.


🔍 If you want to check it out

GitHub:
I’ll add the GitHub link here tomorrow once the restriction lifts 👍

It’s not a SaaS — nothing leaves your server.
Everything runs locally inside your Laravel project.


💬 Feedback welcome

If you try it and have feedback, criticism, improvement ideas, or thoughts about safer ways to manage .env, I’d honestly love to hear them.

And if you’re curious — AMA-style — about:

• why I built it
• how it works internally
• what real-world problems it solved
• what I’d like to improve next

I’m happy to chat 🙂

Thanks for reading!

PS: If my English isn’t perfect everywhere, forgive me — I’m Italian 🇮🇹 and doing my best 😄