7.1 KiB
7.1 KiB
Environment Setup Guide
Panduan lengkap untuk setup environment file CKB Laravel Application dengan file template terpisah untuk local dan production.
📂 File Structure
docker/
├── env.example.local # Template untuk local development
├── env.example.production # Template untuk production
└── (env.example) # File lama, dapat dihapus
🔧 Quick Setup
Local Development
# Setup environment untuk local development
./docker-setup-env.sh local
# Atau manual copy
cp docker/env.example.local .env
Production Deployment
# Setup environment untuk production
./docker-setup-env.sh production
# IMPORTANT: Edit .env dan ganti semua CHANGE_THIS_* values!
nano .env
📋 Template Comparison
🏠 Local Development (env.example.local)
| Setting | Value | Description |
|---|---|---|
APP_ENV |
local |
Development environment |
APP_DEBUG |
true |
Debug mode enabled |
APP_URL |
http://localhost:8000 |
Local URL |
LOG_LEVEL |
debug |
Verbose logging |
DB_DATABASE |
ckb_db |
Development database |
DB_USERNAME |
root |
Simple credentials |
DB_PASSWORD |
root |
Simple credentials |
REDIS_PASSWORD |
null |
No password needed |
MAIL_HOST |
mailhog |
Local mail testing |
QUEUE_CONNECTION |
sync |
Synchronous queue |
TELESCOPE_ENABLED |
true |
Debugging tool enabled |
🚀 Production (env.example.production)
| Setting | Value | Description |
|---|---|---|
APP_ENV |
production |
Production environment |
APP_DEBUG |
false |
Debug mode disabled |
APP_URL |
https://bengkel.digitaloasis.xyz |
Production domain |
LOG_LEVEL |
error |
Error-only logging |
DB_DATABASE |
ckb_production |
Production database |
DB_USERNAME |
ckb_user |
Secure username |
DB_PASSWORD |
CHANGE_THIS_* |
Must be changed! |
REDIS_PASSWORD |
CHANGE_THIS_* |
Must be changed! |
MAIL_HOST |
smtp.gmail.com |
Real SMTP server |
QUEUE_CONNECTION |
redis |
Redis-based queue |
TELESCOPE_ENABLED |
false |
Debugging tool disabled |
🔐 Security Configuration for Production
Required Changes
MUST CHANGE these values in production .env:
# Strong database passwords
DB_PASSWORD=your_super_secure_password_here
DB_ROOT_PASSWORD=your_root_password_here
# Redis security
REDIS_PASSWORD=your_redis_password_here
# Mail configuration
MAIL_USERNAME=your-email@domain.com
MAIL_PASSWORD=your-app-specific-password
Optional but Recommended
# AWS S3 for file storage
AWS_ACCESS_KEY_ID=your-aws-key
AWS_SECRET_ACCESS_KEY=your-aws-secret
# Real-time features
PUSHER_APP_ID=your-pusher-app-id
PUSHER_APP_KEY=your-pusher-key
PUSHER_APP_SECRET=your-pusher-secret
🛠️ Environment Helper Script
Usage
# Setup local environment
./docker-setup-env.sh local
# Setup production environment
./docker-setup-env.sh production
# Show current environment info
./docker-setup-env.sh
Features
- ✅ Auto-backup existing
.envbefore changes - ✅ Environment validation checks required variables
- ✅ Security warnings for production misconfiguration
- ✅ Configuration summary shows current settings
- ✅ Next steps guidance for deployment
📊 Environment Comparison
Local Development Features
- 🐛 Debug Mode: Full error reporting and debugging tools
- 📧 MailHog: Local email testing server
- 🗄️ Simple DB: Basic MySQL credentials
- 🔓 No SSL: HTTP-only for speed
- 🧪 Development Tools: Telescope, Debugbar enabled
- ⚡ Sync Queue: Immediate processing for testing
Production Features
- 🔒 Security First: Strong passwords and encryption
- 📧 Real SMTP: Professional email delivery
- 🗄️ Secure DB: Production-grade credentials
- 🔐 SSL/HTTPS: Let's Encrypt certificates
- 📊 Monitoring: Error-only logging
- 🚀 Redis Queue: Background job processing
🚨 Common Issues & Solutions
1. "CHANGETHIS*" Values in Production
Problem: Forgot to change template values
# Check for remaining template values
grep "CHANGE_THIS" .env
Solution:
# Use the helper script to check
./docker-setup-env.sh
# It will warn about CHANGE_THIS_* values
2. Wrong Environment File
Problem: Using local config in production
# Check current environment
grep "APP_ENV=" .env
Solution:
# Recreate with correct template
./docker-setup-env.sh production
3. Missing Environment Variables
Problem: Laravel errors about missing config
# Validate current .env
./docker-setup-env.sh validate
Solution: Check required variables list and add missing ones
📝 Environment Variables Reference
Core Application
APP_NAME="CKB Bengkel System"
APP_ENV=production|local
APP_KEY=base64:...
APP_DEBUG=true|false
APP_URL=https://domain.com
Database
DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=ckb_production|ckb_db
DB_USERNAME=username
DB_PASSWORD=password
DB_ROOT_PASSWORD=root_password
Cache & Session
REDIS_HOST=redis
REDIS_PASSWORD=password|null
REDIS_PORT=6379
CACHE_DRIVER=redis
SESSION_DRIVER=redis
QUEUE_CONNECTION=redis|sync
Mail Configuration
MAIL_MAILER=smtp
MAIL_HOST=smtp.domain.com
MAIL_PORT=587
MAIL_USERNAME=email@domain.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=noreply@domain.com
MAIL_FROM_NAME="${APP_NAME}"
Security
TRUSTED_PROXIES=*
SESSION_SECURE_COOKIE=true
SESSION_SAME_SITE=strict
🔄 Migration Guide
From Old Single Template
If you're migrating from the old docker/env.example:
# Backup current .env
cp .env .env.backup
# Choose appropriate template
./docker-setup-env.sh local # for development
./docker-setup-env.sh production # for production
# Compare and migrate custom settings
diff .env.backup .env
📞 Support
For environment setup issues:
- Documentation: This file
- Helper Script:
./docker-setup-env.sh - Validation: Built-in security checks
- Backup: Automatic .env backup before changes
💡 Pro Tip: Always use the helper script ./docker-setup-env.sh instead of manual copying to ensure proper configuration and security checks!