How to manage environment variables and secrets
Updated 11/29/2026
Passwords, API keys and other secrets should never be written in code or pushed to Git. Their place is in environment variables.
The .env file
Most frameworks read configuration from a .env file:
DB_PASSWORD=secret_password
API_KEY=your_key
Do not push .env to Git
Add it to .gitignore and put only a .env.example without real values in the repo.
echo ".env" >> .gitignore
Strict permissions
chmod 600 .env
Only the owner can read the file, see file permissions.
System-level variables
For systemd services, you can put variables in the service unit:
Environment="API_KEY=your_key"
In CI/CD
Secrets go in the CI/CD system's secrets interface, not in the workflow files, see CI/CD pipeline. If a secret accidentally reached Git, change it immediately, Git history keeps it.
Put this guide into practice on your own VPS
EU cloud servers, billed hourly, ready in minutes, with one-click installs for dozens of apps.
See pricingRelated tutorials
Error tracking for your applications with GlitchTip
Catch production exceptions with the Sentry SDKs on a small server: the project, the DSN, alerts and uptime.
Updated 11/29/2026Dev environmentsTest your application's email with smtp4dev
Send the email from Laravel, WordPress, Node or Python to a test SMTP server and read it in a web inbox, without it ever reaching real customers.
Updated 11/29/2026Dev environmentsHow to set up a staging environment
Test changes on a copy of production before shipping them, to avoid surprises.
Updated 11/29/2026