# Production Deployment Guide - Perizinan API Integration ## 🚀 Quick Deployment ### 1. Upload Files to Server Upload semua files ke server Linux di directory `/var/www/perling` (atau sesuai setup Anda). ### 2. Run Deployment Script ```bash cd /var/www/perling chmod +x deploy-production.sh ./deploy-production.sh ``` ### 3. Update Environment Variables Edit file `.env` dan update: ```env APP_ENV=production APP_DEBUG=false # Database production DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=perling_production DB_USERNAME=your_db_user DB_PASSWORD=your_db_password # API Credentials (yang sudah ada) PERIZINAN_API_BEARER_TOKEN=f633c4f8e8a84708895bf31c0afdfa68c9079613d18d4edfb1fc6a0019b5f832 PERIZINAN_API_KEY=b06c8ef1-06db-443d-996b-80e8c3374923 ``` ### 4. Setup Cron Job #### Option 1: Laravel Scheduler (Recommended) ```bash # Edit crontab sudo crontab -e # Add this line (runs every minute): * * * * * cd /var/www/perling && ./run-scheduler.sh >/dev/null 2>&1 ``` #### Option 2: Direct Sync ```bash # Edit crontab sudo crontab -e # Add this line (runs daily at midnight): 0 0 * * * cd /var/www/perling && ./sync-perizinan.sh >/dev/null 2>&1 ``` ## 🔧 Manual Commands ### Test API Connection ```bash cd /var/www/perling php artisan perizinan:sync pertek ``` ### Check Synced Data ```bash php artisan perizinan:check ``` ### View Logs ```bash # Cron logs tail -f storage/logs/cron.log # Laravel application logs tail -f storage/logs/laravel.log # Scheduler logs (if using Option 1) tail -f storage/logs/scheduler.log ``` ### View Cron Job Status ```bash # View current crontab crontab -l # View cron service logs sudo journalctl -u cron -f ``` ## 🐛 Troubleshooting ### Permission Issues ```bash # Fix storage permissions sudo chown -R www-data:www-data storage/ sudo chmod -R 775 storage/ # Fix cache permissions sudo chown -R www-data:www-data bootstrap/cache/ sudo chmod -R 775 bootstrap/cache/ ``` ### Database Issues ```bash # Clear config cache php artisan config:clear # Run migrations php artisan migrate --force # Check database connection php artisan tinker --execute="DB::connection()->getPdo();" ``` ### API Connection Issues ```bash # Test API manually curl -X GET "https://wsdev.jakarta.go.id/gateway/DataPerizinanLingkungan/1.0/summary_by_status?kategori=pertek" \ -H "Authorization: Bearer f633c4f8e8a84708895bf31c0afdfa68c9079613d18d4edfb1fc6a0019b5f832" \ -H "x-Gateway-APIKey: b06c8ef1-06db-443d-996b-80e8c3374923" ``` ### Cron Job Not Running ```bash # Check if cron service is running sudo systemctl status cron # Start cron service if stopped sudo systemctl start cron # Check cron logs sudo tail -f /var/log/cron.log ``` ## 📊 Monitoring ### Daily Health Check ```bash # Check if data was synced today php artisan perizinan:check # Check latest logs tail -20 storage/logs/cron.log ``` ### Weekly Review ```bash # Check database records count php artisan tinker --execute="echo App\Models\PerizinanStatus::count() . ' total records';" # Check logs for errors grep -i error storage/logs/laravel.log | tail -10 ``` ## 🔐 Security Notes 1. **File Permissions**: Ensure proper permissions for Laravel 2. **Database**: Use strong password and limit access 3. **API Keys**: Keep credentials secure, don't commit to version control 4. **Logs**: Regularly rotate and clean up log files 5. **SSL**: Use HTTPS in production ## 📈 Performance Tips 1. **Database Indexing**: Already added in migration 2. **Log Rotation**: Setup logrotate for Laravel logs 3. **Caching**: Enable OPcache for PHP 4. **Queue**: Consider using Redis for Laravel queues if needed ## 🎯 Success Criteria ✅ Cron job runs without errors ✅ Data syncs daily at midnight ✅ Dashboard shows real API data ✅ Logs are clean without errors ✅ Database grows with daily records ✅ API connection is stable