Command Line Tools
Configuration Management Guide
Configuration Management Guide
Section titled “Configuration Management Guide”This guide covers configuration management in Wheels, including working with environment variables, settings files, and the CLI tools for managing configuration.
Overview
Section titled “Overview”Wheels provides flexible configuration management through:
- Environment-specific settings files
- Environment variables (.env files)
- CLI commands for configuration management
- Security best practices
Environment Variables
Section titled “Environment Variables”.env File Format
Section titled “.env File Format”Wheels supports two formats for .env files:
Properties Format (Recommended)
Section titled “Properties Format (Recommended)”# Database ConfigurationDB_HOST=localhostDB_PORT=3306DB_NAME=myapp_developmentDB_USER=wheelsDB_PASSWORD=secretpassword
# Application SettingsWHEELS_ENV=developmentRELOAD_PASSWORD=myreloadpasswordSECRET_KEY=a1b2c3d4e5f6g7h8i9j0
# Feature FlagsDEBUG_MODE=trueCACHE_ENABLED=falseJSON Format
Section titled “JSON Format”{ "DB_HOST": "localhost", "DB_PORT": 3306, "DB_NAME": "myapp_development", "DB_USER": "wheels", "DB_PASSWORD": "secretpassword", "WHEELS_ENV": "development", "DEBUG_MODE": true}Environment-Specific Files
Section titled “Environment-Specific Files”Wheels automatically loads environment-specific .env files:
.env- Base configuration (always loaded first).env.{environment}- Environment-specific overrides (loaded second)
Example structure:
myapp/├── .env # Base configuration├── .env.development # Development overrides├── .env.testing # Testing overrides├── .env.production # Production settings└── .gitignore # MUST exclude .env files!Variable Interpolation
Section titled “Variable Interpolation”Use ${VAR} syntax to reference other variables:
APP_NAME=MyWheelsAppAPP_ENV=development
# Database URLs with interpolationDB_HOST=localhostDB_PORT=3306DB_NAME=${APP_NAME}_${APP_ENV}DB_URL=mysql://${DB_HOST}:${DB_PORT}/${DB_NAME}
# API endpointsAPI_BASE_URL=https://api.example.comAPI_USERS_URL=${API_BASE_URL}/usersAPI_ORDERS_URL=${API_BASE_URL}/ordersType Casting
Section titled “Type Casting”Wheels automatically casts certain values:
# Booleans (cast to true/false)DEBUG_MODE=trueCACHE_ENABLED=false
# Numbers (cast to numeric values)MAX_CONNECTIONS=100CACHE_TTL=3600REQUEST_TIMEOUT=30
# Strings (remain as strings)APP_NAME=MyAppAPI_KEY=abc123def456Using Environment Variables in Settings
Section titled “Using Environment Variables in Settings”Access environment variables in your settings files:
// Using application.env structset(dataSourceName = application.env['DB_NAME']);set(dataSourceUserName = application.env['DB_USER']);set(dataSourcePassword = application.env['DB_PASSWORD']);
// With defaultsset(cacheQueries = application.env['CACHE_ENABLED'] ?: false);set(reloadPassword = application.env['RELOAD_PASSWORD'] ?: 'defaultpassword');
// Environment-specific logicif (application.env['WHEELS_ENV'] == 'production') { set(showDebugInformation = false); set(cacheFileChecking = true);}Configuration Files
Section titled “Configuration Files”Directory Structure
Section titled “Directory Structure”config/├── settings.cfm # Base configuration├── development/│ └── settings.cfm # Development overrides├── testing/│ └── settings.cfm # Testing overrides├── production/│ └── settings.cfm # Production overrides└── maintenance/ └── settings.cfm # Maintenance mode settingsSettings Precedence
Section titled “Settings Precedence”Settings are loaded in this order (later overrides earlier):
- Framework defaults
config/settings.cfmconfig/{environment}/settings.cfm- Plugin settings
- Runtime
set()calls
Common Configuration Patterns
Section titled “Common Configuration Patterns”Database Configuration
Section titled “Database Configuration”set(dataSourceName = application.env['DB_NAME'] ?: 'wheelstutorial');set(dataSourceUserName = application.env['DB_USER'] ?: 'root');set(dataSourcePassword = application.env['DB_PASSWORD'] ?: '');Environment-Specific Settings
Section titled “Environment-Specific Settings”// Production optimizationsset(cacheQueries = true);set(cachePartials = true);set(cachePages = true);set(cacheActions = true);set(cacheImages = true);set(cacheModelConfig = true);set(cacheControllerConfig = true);set(cacheRoutes = true);set(cacheDatabaseSchema = true);set(cacheFileChecking = false);
// Securityset(showDebugInformation = false);set(showErrorInformation = false);
// Error handlingset(sendEmailOnError = true);set(errorEmailAddress = application.env['ERROR_EMAIL']);CLI Configuration Commands
Section titled “CLI Configuration Commands”Dumping Configuration
Section titled “Dumping Configuration”Export current configuration:
# View current config (masked)wheels config dump
# Export production config as JSONwheels config dump production --format=json --output=prod-config.json
# Export as .env formatwheels config dump --format=env --output=config.env
# Export without masking (careful!)wheels config dump --no-maskChecking Configuration
Section titled “Checking Configuration”Validate configuration for issues:
# Basic checkwheels config check
# Check production with fixeswheels config check production --fix
# Verbose output with suggestionswheels config check --verboseCommon checks performed:
- Missing required settings
- Hardcoded sensitive values
- Production security settings
- Database configuration
- Caching optimizations
Comparing Environments
Section titled “Comparing Environments”Find differences between environments:
# Full comparisonwheels config diff development production
# Show only differenceswheels config diff development production --changes-only
# Export as JSONwheels config diff testing production --format=json > diff.jsonManaging Secrets
Section titled “Managing Secrets”Generate secure secrets:
# Generate and displaywheels secretwheels secret --type=base64 --length=48
# Save to .envwheels secret --save-to-env=SECRET_KEYwheels secret --type=uuid --save-to-env=API_KEY
# Multiple secretswheels secret --save-to-env=SESSION_SECRETwheels secret --save-to-env=CSRF_TOKENwheels secret --save-to-env=ENCRYPTION_KEYEnvironment Variable Management
Section titled “Environment Variable Management”Setting Variables
Section titled “Setting Variables”# Set single variablewheels env set DB_HOST=localhost
# Set multiplewheels env set DB_HOST=localhost DB_PORT=3306 DB_NAME=myapp
# Update production filewheels env set --file=.env.production API_URL=https://api.example.comValidating Files
Section titled “Validating Files”# Basic validationwheels env validate
# Check required variableswheels env validate --required=DB_HOST,DB_USER,DB_PASSWORD
# Validate productionwheels env validate --file=.env.production --verboseMerging Files
Section titled “Merging Files”# Merge for deploymentwheels env merge .env .env.production --output=.env.deployed
# Preview mergewheels env merge .env.defaults .env.local --dry-runSecurity Best Practices
Section titled “Security Best Practices”1. Never Commit Secrets
Section titled “1. Never Commit Secrets”Always add .env files to .gitignore:
# Environment files.env.env.*!.env.example!.env.defaults2. Use Strong Secrets
Section titled “2. Use Strong Secrets”Generate cryptographically secure values:
# For session secretswheels secret --type=hex --length=64 --save-to-env=SESSION_SECRET
# For API keyswheels secret --type=base64 --length=48 --save-to-env=API_SECRET
# For passwordswheels secret --type=alphanumeric --length=323. Validate Production Config
Section titled “3. Validate Production Config”Run checks before deployment:
# Full production checkwheels config check production --verbose
# Required checkswheels env validate --file=.env.production \ --required=DB_HOST,DB_USER,DB_PASSWORD,SECRET_KEY,RELOAD_PASSWORD4. Mask Sensitive Output
Section titled “4. Mask Sensitive Output”Always use masking in logs/output:
// In your codewriteOutput("Database: #application.env['DB_NAME']#");writeOutput("Password: ***MASKED***"); // Never output passwords5. Environment-Specific Secrets
Section titled “5. Environment-Specific Secrets”Use different secrets per environment:
SECRET_KEY=dev_secret_key_only_for_local
# .env.productionSECRET_KEY=prod_0a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0Common Patterns
Section titled “Common Patterns”Multi-Environment Setup
Section titled “Multi-Environment Setup”# 1. Create base configwheels env set WHEELS_ENV=development DB_NAME=myapp_dev
# 2. Create production configwheels env set --file=.env.production \ WHEELS_ENV=production \ DB_NAME=myapp_prod \ DB_HOST=prod.database.com
# 3. Create testing configwheels env set --file=.env.testing \ WHEELS_ENV=testing \ DB_NAME=myapp_test
# 4. Validate allwheels env validatewheels env validate --file=.env.productionwheels env validate --file=.env.testingDeployment Configuration
Section titled “Deployment Configuration”# 1. Merge configs for deploymentwheels env merge .env.defaults .env.production --output=.env.deploy
# 2. Validate merged configwheels env validate --file=.env.deploy \ --required=DB_HOST,DB_USER,DB_PASSWORD,SECRET_KEY
# 3. Check securitywheels config check production --verboseLocal Development
Section titled “Local Development”# 1. Copy example filecp .env.example .env
# 2. Set local valueswheels env set DB_HOST=localhost DB_USER=root DB_PASSWORD=
# 3. Generate secretswheels secret --save-to-env=SECRET_KEYwheels secret --save-to-env=RELOAD_PASSWORD
# 4. Validatewheels env validateTroubleshooting
Section titled “Troubleshooting”Environment Variables Not Loading
Section titled “Environment Variables Not Loading”- Check file exists and is readable
- Verify format (properties vs JSON)
- Check for syntax errors:
Terminal window wheels env validate
Wrong Environment Loading
Section titled “Wrong Environment Loading”- Check WHEELS_ENV variable:
Terminal window wheels env show --key=WHEELS_ENV - Verify environment detection order:
.envfile WHEELS_ENV- System environment WHEELS_ENV
- Default to ‘development’
Interpolation Not Working
Section titled “Interpolation Not Working”- Ensure variables are defined before use
- Check syntax:
${VAR_NAME} - Maximum 10 interpolation passes (prevent loops)
Sensitive Values Exposed
Section titled “Sensitive Values Exposed”- Run security check:
Terminal window wheels config check --verbose - Move hardcoded values to .env
- Use
application.envreferences
Best Practices Summary
Section titled “Best Practices Summary”- Use .env files for all environment-specific values
- Never commit secrets - use .gitignore
- Generate strong secrets with
wheels secret - Validate configuration before deployment
- Use interpolation to reduce duplication
- Environment-specific files for overrides
- Check security regularly with CLI tools
- Document required variables in .env.example
- Mask sensitive values in output
- Test configuration changes in development first