When a server hosts a dozen apps, secrets pile up: database passwords, API keys, app keys, mail credentials. Most live in .env files nobody has looked at in years. This is the process we used to get control, with every app name below invented.
1. Where one .env file ends up
A single .env does not stay single. It gets copied to .env.bak and .env.old, ends up in a database dump or git history, gets printed by a debug page, and sits readable by other sites sharing the same web user. Worse, the same password is often reused across apps, so one leak opens many doors.

Most leaks are not clever attacks. They are copies nobody remembered making.
2. Inventory first, and never print a value
- Scan for
.env, config files and service units. - Record names only: key names and file paths, never values.
- Hash and group: the same hash means the same secret reused.
- Report: who shares what, and what to rotate first.

The output is a table of names and reuse counts, so it is safe to paste in a ticket or a chat. A reused secret is one secret with several addresses. Fix those first.
3. Rotate a database password without downtime
- Set a new password on the database account.
- Write it to the app’s
.env. - Reload PHP-FPM or the app, not a hard restart.
- Verify real URLs return 200 and logs are clean.

If it fails, restore the old value from the snapshot and reload again. If healthy, log it and move to the next app.
Two traps we hit. First, write the exact value from a script instead of editing by hand, because a stray character breaks logins. Second, sed -i can drop a file’s group, so check the mode and owner after every edit.
4. Pick the lightest store that fits

- A file with mode 640: owner plus the site group. Free and simple.
- systemd credentials: passed to one service, not left in the environment. Good for daemons.
- SOPS + age: an encrypted file in git, decrypted at deploy. Good for small teams.
- A vault server: Vaultwarden for people, OpenBao or Vault for machines. Adds audit, leases and dynamic secrets, and something to run and back up.
Start on the left. Move right only when you feel a real limit.
5. Each site reads its own file and nobody else’s
Pair secrets with per-site PHP-FPM pools: each pool runs as its own user, and each .env is owned by the deploy user, grouped to that site, mode 640 or 600, with no world access. Avoid symlinks to files you do not own, because a recursive chown follows them.

Check after every change: ls -l, then a real request.
6. Make it a habit, not a project
Inventory quarterly with names only. Rotate reused and old secrets first. Verify URLs, logs and scheduled jobs. Record dates in a plan file.

Rotate out of schedule when someone leaves, a laptop is lost, a file was exposed or a backup leaked.
Takeaways
- List names, never values.
- Fix reused secrets first.
- Rotate with a snapshot, a reload and a verify step.
- Use the lightest store that meets your need.
- Secrets are never finished. They are maintained.



