Object Relational Mapping
Creating Records
Reading Records
Updating Records
Deleting Records
Column Statistics
Dynamic Finders
Getting Paginated Data
Associations
Nested Properties
Object Validation
Object Callbacks
Calculated Properties
Transactions
Dirty Records
Soft Delete
Automatic Time Stamps
Using Multiple Data Sources
wheels env setup
Setup a new environment configuration for your Wheels application with comprehensive database, template, and configuration options.
Synopsis
wheels env setup environment=<name> [options]
Description
The wheels env setup
command creates and configures new environments for your Wheels application. It generates:
- Environment-specific
.env.[environment]
files with database and server settings - Configuration files at
config/[environment]/settings.cfm
with Wheels settings - Template-specific files (Docker, Vagrant) if requested
- Server.json updates for environment-specific configurations
The command supports copying configurations from existing environments and allows full customization of database types, templates, and framework settings.
Arguments
| Argument | Description | Required |
|----------|-------------|----------|
| environment
| Environment name (e.g., development, staging, production, testing) | Yes |
Note: Always use named parameter syntax: environment=name
to avoid parameter conflicts.
Options
| Option | Description | Default | Valid Values |
|--------|-------------|---------|--------------|
| --template
| Deployment template type | local
| local
, docker
, vagrant
|
| --dbtype
| Database type | h2
| h2
, mysql
, postgres
, mssql
|
| --database
| Custom database name | wheels_[environment]
| Any valid database name |
| --datasource
| ColdFusion datasource name | wheels_[environment]
| Any valid datasource name |
| --base
| Base environment to copy from | (none) | Any existing environment name |
| --force
| Overwrite existing environment | false
| true
, false
|
| --debug
| Enable debug settings | false
| true
, false
|
| --cache
| Enable cache settings | false
| true
, false
|
| --reloadPassword
| Custom reload password | wheels[environment]
| Any string |
| --help
| Show detailed help information | false
| - |
Examples
Basic Environment Setup
# Create development environment with H2 database (default)
wheels env setup environment=development
# Create staging environment with MySQL
wheels env setup environment=staging --dbtype=mysql
# Create production environment with PostgreSQL and caching enabled
wheels env setup environment=production --dbtype=postgres --cache=true --debug=false
Using Base Environment
# Copy settings from development environment but use PostgreSQL
wheels env setup environment=testing --base=development --dbtype=postgres
# Create staging environment based on production settings
wheels env setup environment=staging --base=production --database=staging_db
# Create QA environment with custom settings
wheels env setup environment=qa --base=development --dbtype=mysql --debug=true --cache=false
Advanced Configuration
# Setup with custom database and datasource names
wheels env setup environment=integration --dbtype=mysql --database=wheels_integration_db --datasource=integration_ds
# Setup with specific reload password and debugging
wheels env setup environment=dev --debug=true --reloadPassword=mypassword123 --force
# Docker environment setup
wheels env setup environment=docker-dev --template=docker --dbtype=postgres --database=wheels_docker
Template-Based Setups
# Local development (default)
wheels env setup environment=dev --template=local --dbtype=h2
# Docker containerized environment
wheels env setup environment=docker-staging --template=docker --dbtype=mysql
# Vagrant VM environment
wheels env setup environment=vm-test --template=vagrant --dbtype=postgres
What It Creates
1. Environment Variables File (.env.[environment]
)
For H2 database:
## Wheels Environment: development
## Generated on: 2025-01-18 12:30:00
## Application Settings
WHEELS_ENV=development
WHEELS_RELOAD_PASSWORD=wheelsdevelopment
## Database Settings
DB_TYPE=h2
DB_DRIVER=H2
DB_HOST=
DB_NAME=./db/wheels_development
DB_USER=sa
DB_PASSWORD=
## Server Settings
SERVER_PORT=8080
SERVER_CFENGINE=lucee5
For MySQL database:
## Wheels Environment: production
## Generated on: 2025-01-18 12:30:00
## Application Settings
WHEELS_ENV=production
WHEELS_RELOAD_PASSWORD=wheelsproduction
## Database Settings
DB_TYPE=mysql
DB_DRIVER=MySQL
DB_HOST=localhost
DB_PORT=3306
DB_NAME=wheels_production
DB_USER=wheels
DB_PASSWORD=wheels_password
## Server Settings
SERVER_PORT=8080
SERVER_CFENGINE=lucee5
2. Configuration File (config/[environment]/settings.cfm
)
<cfscript>
// Environment: production
// Generated: 2025-01-18 12:30:00
// Debug Mode: Disabled
// Cache Mode: Enabled
// Database settings
set(dataSourceName="wheels_production");
// Environment settings
set(environment="production");
// Debug settings - controlled by debug argument
set(showDebugInformation=false);
set(showErrorInformation=false);
// Caching settings - controlled by cache argument
set(cacheFileChecking=true);
set(cacheImages=true);
set(cacheModelInitialization=true);
set(cacheControllerInitialization=true);
set(cacheRoutes=true);
set(cacheActions=true);
set(cachePages=true);
set(cachePartials=true);
set(cacheQueries=true);
// Security
set(reloadPassword="wheelsproduction");
// URLs
set(urlRewriting="partial");
// Environment-specific settings
set(sendEmailOnError=true);
set(errorEmailAddress="dev-team@example.com");
</cfscript>
3. Template-Specific Files
Docker Template (--template=docker
)
Creates:
docker-compose.[environment].yml
Dockerfile
(if not exists)
Vagrant Template (--template=vagrant
)
Creates:
Vagrantfile.[environment]
vagrant/provision-[environment].sh
Database Types
H2 (Embedded)
- Use Case: Development, testing, quick prototyping
- Connection: No network port required (embedded)
- Database Path:
./db/[database_name]
- Default Credentials: username=
sa
, password=(empty)
wheels env setup environment=dev --dbtype=h2 --database=my_dev_db
MySQL
- Use Case: Production, staging environments
- Default Port: 3306
- Default Credentials: username=
wheels
, password=wheels_password
wheels env setup environment=prod --dbtype=mysql --database=wheels_production
PostgreSQL
- Use Case: Production, complex applications
- Default Port: 5432
- Default Credentials: username=
wheels
, password=wheels_password
wheels env setup environment=staging --dbtype=postgres
Microsoft SQL Server
- Use Case: Enterprise environments
- Default Port: 1433
- Default Credentials: username=
sa
, password=Wheels_Pass123!
wheels env setup environment=enterprise --dbtype=mssql
Base Environment Copying
When using --base
, the command copies configuration from an existing environment:
What Gets Copied:
- Database host, username, and password
- Server configuration (port, CF engine)
- Custom environment variables
What Gets Modified:
- Environment name
- Database name (becomes
wheels_[new_environment]
) - Database type, driver, and port (based on
--dbtype
) - Reload password (becomes
wheels[new_environment]
)
# Copy from production but use H2 for testing
wheels env setup environment=test --base=production --dbtype=h2
# Copy from development but use different database name
wheels env setup environment=feature-branch --base=development --database=feature_test_db
Environment Naming Conventions
Recommended Names:
development
ordev
- Local developmenttesting
ortest
- Automated testingstaging
- Pre-production testingproduction
orprod
- Live environmentqa
- Quality assurancedemo
- Client demonstrations
Custom Names:
wheels env setup environment=feature-auth --base=development
wheels env setup environment=performance-test --base=production --cache=false
wheels env setup environment=client-demo --base=staging
Template Options
Local Template (default)
Best for traditional server deployments:
wheels env setup environment=prod --template=local --dbtype=mysql
Docker Template
Creates containerized environment:
wheels env setup environment=docker-dev --template=docker --dbtype=postgres
Generated docker-compose.docker-dev.yml
:
version: '3.8'
services:
app:
build: .
ports:
- "8080:8080"
environment:
- WHEELS_ENV=docker-dev
- DB_TYPE=postgres
- DB_HOST=db
- DB_PORT=5432
- DB_NAME=wheels
- DB_USER=wheels
- DB_PASSWORD=wheels_password
volumes:
- .:/app
depends_on:
- db
db:
image: postgres:14
ports:
- "5432:5432"
environment:
POSTGRES_DB=wheels
POSTGRES_USER=wheels
POSTGRES_PASSWORD=wheels_password
volumes:
- db_data:/var/lib/postgresql/data
volumes:
db_data:
Vagrant Template
Creates VM-based environment:
wheels env setup environment=vm-test --template=vagrant --dbtype=mysql
Next Steps After Setup
The command provides environment-specific next steps:
Local Template:
- Switch to environment:
wheels env switch [environment]
- Start server:
box server start
- Access application at: http://localhost:8080
Docker Template:
- Start Docker environment:
docker-compose -f docker-compose.[environment].yml up
- Access application at: http://localhost:8080
- Stop environment:
docker-compose -f docker-compose.[environment].yml down
Vagrant Template:
- Start Vagrant VM:
vagrant up
- Access application at: http://localhost:8080 or http://192.168.56.10:8080
- SSH into VM:
vagrant ssh
- Stop VM:
vagrant halt
Configuration Management
Environment Detection
Update config/environment.cfm
to automatically detect environments:
<cfscript>
// Auto-detect environment based on server name
if (cgi.server_name contains "staging") {
this.env = "staging";
} else if (cgi.server_name contains "test") {
this.env = "testing";
} else if (cgi.server_name contains "demo") {
this.env = "demo";
} else if (cgi.server_name contains "localhost") {
this.env = "development";
} else {
this.env = "production";
}
</cfscript>
Environment Variables Integration
Load .env.[environment]
files in Application.cfc
:
<cfscript>
component extends="wheels.Controller" {
function config() {
// Load environment-specific variables
var envFile = expandPath(".env." & get("environment"));
if (fileExists(envFile)) {
loadEnvironmentFile(envFile);
}
}
private function loadEnvironmentFile(filePath) {
var lines = fileRead(arguments.filePath).listToArray(chr(10));
for (var line in lines) {
if (len(trim(line)) && !line.startsWith("##")) {
var parts = line.listToArray("=");
if (arrayLen(parts) >= 2) {
var key = trim(parts[1]);
var value = trim(parts[2]);
// Set as system property or use in configuration
set(lCase(key), value);
}
}
}
}
}
</cfscript>
Validation and Testing
After creating an environment, validate the setup:
# List all environments to verify creation
wheels env list
# Switch to the new environment
wheels env switch [environment]
# Test database connection
wheels test run --type=core
# Check configuration
wheels env current
Error Handling
Common Issues and Solutions:
Environment already exists:
wheels env setup environment=staging --force
Base environment not found:
# Check available environments
wheels env list
# Use correct base environment name
wheels env setup environment=test --base=development
Database connection issues:
- Verify database credentials in
.env.[environment]
- Check database server is running
- Validate port configuration
Permission issues:
- Ensure write permissions for config directory
- Check file system permissions
Best Practices
1. Environment Naming
- Use consistent, descriptive names
- Avoid spaces and special characters
- Follow team conventions
2. Database Management
- Use separate databases per environment
- Document database naming conventions
- Implement proper backup strategies
3. Security
- Use strong, unique reload passwords
- Never commit sensitive credentials
- Use environment variables for secrets
4. Configuration
- Start with a solid base environment
- Document environment purposes
- Test configurations thoroughly
5. Template Selection
local
: Traditional server deploymentsdocker
: Containerized applicationsvagrant
: Isolated development VMs
Integration Examples
CI/CD Pipeline
# Create testing environment for CI
wheels env setup environment=ci-test --base=production --dbtype=h2 --debug=false
# Create staging environment for deployment testing
wheels env setup environment=staging --base=production --dbtype=mysql --cache=true
Feature Development
# Create feature-specific environment
wheels env setup environment=feature-login --base=development --database=login_feature_db
# Create A/B testing environments
wheels env setup environment=variant-a --base=production --database=variant_a_db
wheels env setup environment=variant-b --base=production --database=variant_b_db
Troubleshooting
Configuration File Issues
- Check syntax in generated
settings.cfm
- Verify file permissions in config directory
- Review environment variable formats
Database Connection Problems
- Verify database server is running
- Check credentials in
.env.[environment]
- Test connection manually
- Review port configurations (remember H2 has no port)
Environment Detection
- Check
config/environment.cfm
logic - Verify server variables
- Test detection rules manually
Performance Considerations
Development Environments
- Enable debugging for detailed information
- Disable caching for hot reload
- Use H2 for fast setup and teardown
Production Environments
- Disable debugging for performance
- Enable all caching options
- Use optimized database configurations
See Also
- wheels env list - List all environments
- wheels env switch - Switch between environments
- wheels env current - Show current environment
- Environment Configuration Guide
- Synopsis
- Arguments
- Options
- Examples
- Basic Environment Setup
- Using Base Environment
- Advanced Configuration
- Template-Based Setups
- What It Creates
-
1. Environment Variables File (
.env.[environment]
) -
2. Configuration File (
config/[environment]/settings.cfm
) - 3. Template-Specific Files
- Database Types
- H2 (Embedded)
- MySQL
- PostgreSQL
- Microsoft SQL Server
- Base Environment Copying
- What Gets Copied:
- What Gets Modified:
- Environment Naming Conventions
- Recommended Names:
- Custom Names:
- Template Options
- Local Template (default)
- Docker Template
- Vagrant Template
- Next Steps After Setup
- Local Template:
- Docker Template:
- Vagrant Template:
- Configuration Management
- Environment Detection
- Environment Variables Integration
- Validation and Testing
- Error Handling
- Common Issues and Solutions:
- Best Practices
- 1. Environment Naming
- 2. Database Management
- 3. Security
- 4. Configuration
- 5. Template Selection
- Integration Examples
- CI/CD Pipeline
- Feature Development
- Troubleshooting
- Configuration File Issues
- Database Connection Problems
- Environment Detection
- Performance Considerations
- Development Environments
- Production Environments
- See Also