How to manage environment variables and secrets
Updated 7/20/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
How to create a systemd service for your app
Make your app start automatically and restart itself if it stops, with a systemd service.
Updated 7/20/2026Dev environmentsHow to keep sessions running after disconnect with tmux
tmux keeps your terminal sessions alive even after you close SSH, ideal for long-running tasks.
Updated 7/20/2026Dev environmentsHow to install PHP (multiple versions) and Composer
Install the PHP version your project needs, along with Composer for package management.
Updated 7/20/2026