Version 0.9.9 | Managing development, staging, and production environments
nself supports multiple environments with cascading configuration. This guide covers setting up and managing environments for your project.
| Environment |
Purpose |
Configuration |
local |
Developer machine |
.env.dev + .env.local
|
staging |
Testing/QA |
.env.dev + .env.staging
|
production |
Live users |
.env.dev + .env.prod + .secrets
|
Files load in order, with later files overriding earlier:
.env.dev # Base config (committed)
โ
.env.local # Local overrides (gitignored)
โ
.env.staging # Staging overrides
โ
.env.prod # Production overrides
โ
.secrets # Sensitive credentials
# Create project
nself init
# Base configuration
cp .env.example .env.dev
# Local overrides (gitignored)
echo "DEBUG=true" > .env.local
# Create staging environment
nself env create staging
# Configure staging
vi .environments/staging/.env.staging
vi .environments/staging/server.json
# Create production environment
nself env create prod
# Configure production (on server)
vi .env.prod
# Generate secrets (on server)
nself init --secure
# Switch to staging
nself env switch staging
# Switch to production
nself env switch prod
# Switch back to local
nself env switch local
| Variable |
Description |
PROJECT_NAME |
Project identifier |
ENV |
Environment (dev/staging/prod) |
BASE_DOMAIN |
Domain name |
| Variable |
Dev |
Staging |
Prod |
DEBUG |
true |
true |
false |
LOG_LEVEL |
debug |
info |
warn |
SSL_MODE |
mkcert |
letsencrypt |
letsencrypt |
# Pull staging config
nself sync config staging
# Pull production data (anonymized)
nself sync db prod --anonymize
| Role |
Local |
Staging |
Prod |
| Dev |
โ
|
โ |
โ |
| Sr Dev |
โ
|
โ
|
โ |
| Lead |
โ
|
โ
|
โ
|
-
Never commit secrets - Use
.secrets file on server
-
Use cascading config - Base in
.env.dev, overrides per environment
-
Anonymize production data - When syncing to local/staging
-
Separate credentials - Different passwords per environment
-
Test in staging first - Before deploying to production