Environment and Configuration Management in Production
On this page
Why Environment Discipline Prevents Outages
Many production failures are not code bugs but configuration mistakes. Wrong database URL, missing environment variable, incorrect feature flag — configuration drift breaks stable systems.
Symptom
- Works in staging but fails in production
- Unexpected feature behavior
- Connection to wrong database
- Service fails after redeploy without code changes
Root Cause
- Hardcoded values
- Manual configuration edits
- Shared config between environments
- Missing environment variable validation
Environment Separation
- Development
- Staging
- Production
Never reuse production credentials in staging.
Inspect Environment Variables
printenv | sort
Check systemd unit environment:
systemctl show app.service -p Environment
Use Dedicated Config Directories
/etc/appname/ /etc/appname/env/
Systemd EnvironmentFile Example
[Service] EnvironmentFile=/etc/appname/prod.env
Mitigation
- Version configuration templates
- Validate required variables on startup
- Restrict config file permissions
- Automate config provisioning
Drift Detection
diff /etc/appname/prod.env /etc/appname/staging.env
Hardening Strategy
- Immutable infrastructure where possible
- Separate secrets from general config
- Audit configuration changes
- Document environment differences explicitly
Verification Checklist
printenv | grep DATABASE systemctl show app.service -p Environment
- No production secrets in staging
- Config stored outside application directory
- No manual undocumented edits
Why This Matters in Real Infrastructure
Configuration errors scale faster than code bugs. Strict environment separation and controlled config management prevent accidental outages and security incidents during deployment.