DEV Community

Cover image for I built a safer way to manage .env files in Laravel (export, validate, backup, rollback)
Vanni Daghini
Vanni Daghini

Posted on

I built a safer way to 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.

This is not meant as spam 🙂 — 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 old .env

✔ rollback 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>
Enter fullscreen mode Exit fullscreen mode

This creates:

.env.config-manager
Enter fullscreen mode Exit fullscreen mode

Your .env is not modified yet.

Apply the configuration (with automatic backup):

php artisan config-manager:export <project-id> <environment-id> --apply
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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:

https://github.com/Vanni7544/config-manager

Gumroad (commercial ready-to-install package):

https://daghini.gumroad.com/l/ifyzw

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 🙂

This isn’t meant as a promotional post — more a way to share something I built and hopefully learn from the community as well.

Thanks for reading!

❤️ PS

If English isn’t perfect everywhere, forgive me — I’m Italian 🇮🇹 and doing my best 😄 Happy to clarify anything!

Top comments (0)