# 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 ```bash # Setup environment untuk local development ./docker-setup-env.sh local # Atau manual copy cp docker/env.example.local .env ``` ### Production Deployment ```bash # 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`: ```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 ```env # 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 ```bash # 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 `.env` before 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. "CHANGE*THIS*\*" Values in Production **Problem**: Forgot to change template values ```bash # Check for remaining template values grep "CHANGE_THIS" .env ``` **Solution**: ```bash # 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 ```bash # Check current environment grep "APP_ENV=" .env ``` **Solution**: ```bash # Recreate with correct template ./docker-setup-env.sh production ``` ### 3. Missing Environment Variables **Problem**: Laravel errors about missing config ```bash # Validate current .env ./docker-setup-env.sh validate ``` **Solution**: Check required variables list and add missing ones ## ๐Ÿ“ Environment Variables Reference ### Core Application ```env APP_NAME="CKB Bengkel System" APP_ENV=production|local APP_KEY=base64:... APP_DEBUG=true|false APP_URL=https://domain.com ``` ### Database ```env 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 ```env REDIS_HOST=redis REDIS_PASSWORD=password|null REDIS_PORT=6379 CACHE_DRIVER=redis SESSION_DRIVER=redis QUEUE_CONNECTION=redis|sync ``` ### Mail Configuration ```env 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 ```env 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`: ```bash # 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!