Troubleshooting - luckydeva03/desa_karangrejo GitHub Wiki
š ļø Troubleshooting
Panduan mengatasi masalah umum yang mungkin terjadi pada Website Desa Karangrejo.
šÆ Overview
Dokumen ini menyediakan solusi untuk masalah-masalah yang sering terjadi dalam penggunaan sehari-hari website desa, mulai dari issues sederhana hingga yang kompleks.
šØ Masalah Umum & Solusi
š Website Tidak Dapat Diakses
Gejala
- Browser menampilkan "This site can't be reached"
- Timeout error
- Connection refused
Diagnosa
# 1. Check apakah server running
sudo systemctl status nginx
sudo systemctl status php8.2-fpm
# 2. Check port yang terbuka
sudo netstat -tlnp | grep :80
sudo netstat -tlnp | grep :443
# 3. Test DNS resolution
nslookup karangrejo.desa.id
dig karangrejo.desa.id
# 4. Check disk space
df -h
# 5. Check memory usage
free -h
Solusi
# Restart web services
sudo systemctl restart nginx
sudo systemctl restart php8.2-fpm
# Check nginx configuration
sudo nginx -t
# If configuration error, fix and reload
sudo systemctl reload nginx
# Check error logs
sudo tail -f /var/log/nginx/error.log
sudo tail -f /var/log/nginx/karangrejo_error.log
š Website Sangat Lambat
Gejala
- Loading time > 5 detik
- Timeout pada beberapa halaman
- Database query lambat
Diagnosa
# 1. Check CPU usage
top
htop
# 2. Check memory usage
free -h
ps aux --sort=-%mem | head -10
# 3. Check disk I/O
iotop
iostat -x 1
# 4. Check database performance
mysql -u root -p -e "SHOW PROCESSLIST;"
mysql -u root -p -e "SHOW STATUS LIKE 'Slow_queries';"
# 5. Check Laravel logs
tail -f /var/www/desa-karangrejo/storage/logs/laravel.log
Solusi
# 1. Enable OPcache
sudo nano /etc/php/8.2/fpm/php.ini
# Ensure opcache.enable=1
# 2. Clear application cache
cd /var/www/desa-karangrejo
sudo -u www-data php artisan cache:clear
sudo -u www-data php artisan config:cache
sudo -u www-data php artisan route:cache
sudo -u www-data php artisan view:cache
# 3. Restart PHP-FPM
sudo systemctl restart php8.2-fpm
# 4. Check Redis status
redis-cli ping
sudo systemctl restart redis-server
# 5. Optimize database
mysql -u root -p desa_karangrejo -e "OPTIMIZE TABLE posts, pages, galleries;"
š Login Tidak Bisa / Error 401
Gejala
- "Invalid credentials" padahal password benar
- Redirect loop setelah login
- Session expired terus-menerus
Diagnosa
# 1. Check session configuration
grep -i session /var/www/desa-karangrejo/.env
# 2. Check session files
ls -la /var/www/desa-karangrejo/storage/framework/sessions/
# 3. Check Redis connection (if using Redis sessions)
redis-cli ping
redis-cli keys "laravel_session:*"
# 4. Check application logs
tail -f /var/www/desa-karangrejo/storage/logs/laravel.log | grep -i auth
Solusi
# 1. Clear sessions
cd /var/www/desa-karangrejo
sudo -u www-data php artisan session:table # if using database sessions
sudo -u www-data php artisan migrate
# Or clear session files
sudo rm -rf storage/framework/sessions/*
# 2. Clear auth cache
sudo -u www-data php artisan cache:forget users
sudo -u www-data php artisan cache:clear
# 3. Reset user password (if needed)
sudo -u www-data php artisan tinker
# User::where('email', '[email protected]')->first()->update(['password' => Hash::make('newpassword')]);
# 4. Check app key
sudo -u www-data php artisan key:generate
š Upload File Gagal
Gejala
- "File too large" error
- Upload stuck/tidak selesai
- Permission denied error
Diagnosa
# 1. Check upload limits
grep -i upload /etc/php/8.2/fpm/php.ini
grep -i post_max /etc/php/8.2/fpm/php.ini
grep -i max_execution /etc/php/8.2/fpm/php.ini
# 2. Check Nginx upload limit
grep -i client_max_body_size /etc/nginx/sites-available/karangrejo.desa.id
# 3. Check storage permissions
ls -la /var/www/desa-karangrejo/storage/app/
ls -la /var/www/desa-karangrejo/public/storage/
# 4. Check disk space
df -h /var/www/
Solusi
# 1. Increase PHP upload limits
sudo nano /etc/php/8.2/fpm/php.ini
# upload_max_filesize = 50M
# post_max_size = 50M
# max_execution_time = 300
# 2. Increase Nginx limit
sudo nano /etc/nginx/sites-available/karangrejo.desa.id
# client_max_body_size 50M;
# 3. Fix permissions
sudo chown -R www-data:www-data /var/www/desa-karangrejo/storage
sudo chmod -R 775 /var/www/desa-karangrejo/storage
# 4. Recreate symlink
cd /var/www/desa-karangrejo
sudo -u www-data php artisan storage:link
# 5. Restart services
sudo systemctl restart php8.2-fpm nginx
šļø Database Connection Error
Gejala
- "Database connection failed"
- "SQLSTATE[HY000] [2002] Connection refused"
- "Too many connections"
Diagnosa
# 1. Check MySQL status
sudo systemctl status mysql
# 2. Test database connection
mysql -u desa_user -p -h localhost desa_karangrejo
# 3. Check MySQL connections
mysql -u root -p -e "SHOW STATUS LIKE 'Threads_connected';"
mysql -u root -p -e "SHOW STATUS LIKE 'Max_used_connections';"
# 4. Check MySQL configuration
grep -i max_connections /etc/mysql/mysql.conf.d/mysqld.cnf
# 5. Check MySQL logs
sudo tail -f /var/log/mysql/error.log
Solusi
# 1. Restart MySQL
sudo systemctl restart mysql
# 2. Fix database credentials
cd /var/www/desa-karangrejo
sudo -u www-data cp .env.example .env.backup
# Edit .env file with correct database credentials
# 3. Test connection
sudo -u www-data php artisan migrate:status
# 4. Increase MySQL connections (if needed)
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
# max_connections = 200
sudo systemctl restart mysql
# 5. Optimize database connections in Laravel
# In config/database.php - set appropriate pool size
š§ Email Tidak Terkirim
Gejala
- Email tidak sampai ke penerima
- SMTP authentication failed
- Connection timeout pada SMTP
Diagnosa
# 1. Check email configuration
grep -i MAIL /var/www/desa-karangrejo/.env
# 2. Test SMTP connection
telnet smtp.gmail.com 587
# 3. Check Laravel mail logs
tail -f /var/www/desa-karangrejo/storage/logs/laravel.log | grep -i mail
# 4. Check queue status (if using queues)
cd /var/www/desa-karangrejo
sudo -u www-data php artisan queue:monitor
Solusi
# 1. Verify email credentials
# Update .env file with correct SMTP settings
# 2. Test email sending
cd /var/www/desa-karangrejo
sudo -u www-data php artisan tinker
# Mail::raw('Test email', function($msg) { $msg->to('[email protected]')->subject('Test'); });
# 3. Clear config cache
sudo -u www-data php artisan config:clear
sudo -u www-data php artisan config:cache
# 4. Restart queue workers (if using)
sudo supervisorctl restart desa-karangrejo-worker:*
# 5. Alternative: Use different mail service
# Consider using services like Mailgun, SendGrid, or local postfix
š§ Tools Diagnosa
1. System Health Check Script
#!/bin/bash
# system-health-check.sh
echo "š„ System Health Check - $(date)"
echo "=================================="
# Check services
echo "š Services Status:"
systemctl is-active nginx && echo "ā
Nginx: Running" || echo "ā Nginx: Not running"
systemctl is-active php8.2-fpm && echo "ā
PHP-FPM: Running" || echo "ā PHP-FPM: Not running"
systemctl is-active mysql && echo "ā
MySQL: Running" || echo "ā MySQL: Not running"
systemctl is-active redis-server && echo "ā
Redis: Running" || echo "ā Redis: Not running"
# Check disk space
echo -e "\nš¾ Disk Usage:"
df -h / /var | grep -v Filesystem
# Check memory
echo -e "\nš§ Memory Usage:"
free -h
# Check load average
echo -e "\nā” Load Average:"
uptime
# Check database connection
echo -e "\nšļø Database Connection:"
mysql -u desa_user -p$DB_PASSWORD -e "SELECT 1" desa_karangrejo 2>/dev/null && \
echo "ā
Database: Connected" || echo "ā Database: Connection failed"
# Check website response
echo -e "\nš Website Status:"
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost)
if [ "$HTTP_CODE" = "200" ]; then
echo "ā
Website: Responding (HTTP $HTTP_CODE)"
else
echo "ā Website: Not responding (HTTP $HTTP_CODE)"
fi
# Check SSL certificate
echo -e "\nš SSL Certificate:"
DAYS_UNTIL_EXPIRY=$(echo | openssl s_client -connect karangrejo.desa.id:443 2>/dev/null | \
openssl x509 -noout -enddate | cut -d= -f2 | xargs -I {} date -d {} +%s | \
xargs -I {} expr \( {} - $(date +%s) \) / 86400)
if [ "$DAYS_UNTIL_EXPIRY" -gt 30 ]; then
echo "ā
SSL: Valid for $DAYS_UNTIL_EXPIRY days"
else
echo "ā ļø SSL: Expires in $DAYS_UNTIL_EXPIRY days"
fi
echo -e "\n==============================="
echo "Health check completed"
2. Performance Monitor Script
#!/bin/bash
# performance-monitor.sh
echo "ā” Performance Monitor - $(date)"
echo "==============================="
# CPU usage
echo "š„ CPU Usage:"
top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}'
# Memory usage
echo -e "\nš¾ Memory Usage:"
free | grep Mem | awk '{printf "Used: %.1f%% (%s/%s)\n", $3/$2 * 100.0, $3, $2}'
# Disk I/O
echo -e "\nšæ Disk I/O:"
iostat -d 1 2 | tail -n +4 | grep -E "sda|nvme"
# Network traffic
echo -e "\nš Network Traffic:"
cat /proc/net/dev | grep eth0 | awk '{print "RX: " $2 " bytes, TX: " $10 " bytes"}'
# MySQL processes
echo -e "\nšļø MySQL Processes:"
mysql -u root -p$MYSQL_ROOT_PASSWORD -e "SHOW PROCESSLIST;" 2>/dev/null | wc -l | awk '{print $1 - 1 " active connections"}'
# PHP-FPM status
echo -e "\nš PHP-FPM Status:"
curl -s http://localhost/fpm-status | grep "active processes" || echo "Status page not configured"
# Nginx connections
echo -e "\nš Nginx Connections:"
curl -s http://localhost/nginx-status | grep "Active connections" || echo "Status page not configured"
echo -e "\n=============================="
echo "Performance check completed"
3. Error Log Analyzer
#!/bin/bash
# error-log-analyzer.sh
echo "š Error Log Analysis - $(date)"
echo "==============================="
LOG_DIR="/var/www/desa-karangrejo/storage/logs"
NGINX_LOG="/var/log/nginx/karangrejo_error.log"
PHP_LOG="/var/log/php8.2-fpm.log"
# Laravel errors (last 24 hours)
echo "š“ Laravel Errors (Last 24h):"
if [ -f "$LOG_DIR/laravel.log" ]; then
grep "$(date -d '1 day ago' '+%Y-%m-%d')" "$LOG_DIR/laravel.log" | grep -i error | tail -5
else
echo "No Laravel log found"
fi
# Nginx errors
echo -e "\nš“ Nginx Errors (Last 50):"
if [ -f "$NGINX_LOG" ]; then
tail -50 "$NGINX_LOG" | grep error
else
echo "No Nginx error log found"
fi
# PHP errors
echo -e "\nš“ PHP Errors (Last 20):"
if [ -f "$PHP_LOG" ]; then
tail -20 "$PHP_LOG" | grep -i error
else
echo "No PHP error log found"
fi
# Database errors
echo -e "\nš“ MySQL Errors (Last 10):"
if [ -f "/var/log/mysql/error.log" ]; then
tail -10 /var/log/mysql/error.log
else
echo "No MySQL error log found"
fi
# 404 errors (top 10)
echo -e "\nš Top 404 Errors:"
if [ -f "/var/log/nginx/karangrejo_access.log" ]; then
grep " 404 " /var/log/nginx/karangrejo_access.log | awk '{print $7}' | sort | uniq -c | sort -nr | head -10
else
echo "No access log found"
fi
echo -e "\n=============================="
echo "Error analysis completed"
š Emergency Procedures
1. Website Down - Quick Recovery
#!/bin/bash
# emergency-recovery.sh
echo "šØ EMERGENCY RECOVERY PROCEDURE"
echo "==============================="
# Step 1: Check and restart services
echo "Step 1: Restarting services..."
sudo systemctl restart nginx
sudo systemctl restart php8.2-fpm
sudo systemctl restart mysql
sudo systemctl restart redis-server
sleep 5
# Step 2: Check if services are running
echo "Step 2: Checking services..."
systemctl is-active nginx php8.2-fpm mysql redis-server
# Step 3: Test website
echo "Step 3: Testing website..."
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost)
if [ "$HTTP_CODE" = "200" ]; then
echo "ā
Website is back online"
else
echo "ā Website still down, checking logs..."
tail -10 /var/log/nginx/error.log
fi
# Step 4: Clear caches
echo "Step 4: Clearing caches..."
cd /var/www/desa-karangrejo
sudo -u www-data php artisan cache:clear
sudo -u www-data php artisan config:clear
sudo -u www-data php artisan view:clear
# Step 5: Final test
echo "Step 5: Final test..."
curl -I http://localhost
echo "Emergency recovery completed"
2. Database Recovery
#!/bin/bash
# database-recovery.sh
echo "šļø DATABASE RECOVERY PROCEDURE"
echo "=============================="
DB_NAME="desa_karangrejo"
BACKUP_DIR="/secure/backups/mysql"
# Step 1: Check database status
echo "Step 1: Checking database..."
mysql -u root -p -e "USE $DB_NAME; SELECT COUNT(*) FROM posts;" 2>/dev/null
if [ $? -eq 0 ]; then
echo "ā
Database seems accessible"
else
echo "ā Database issue detected, checking for backups..."
# Step 2: Find latest backup
LATEST_BACKUP=$(ls -t $BACKUP_DIR/$DB_NAME*.sql.gz.enc 2>/dev/null | head -1)
if [ -n "$LATEST_BACKUP" ]; then
echo "Found backup: $LATEST_BACKUP"
read -p "Restore from this backup? (yes/no): " confirm
if [ "$confirm" = "yes" ]; then
echo "Restoring database..."
/usr/local/bin/mysql-restore.sh "$LATEST_BACKUP"
fi
else
echo "ā No backup found, manual intervention required"
fi
fi
3. Security Incident Response
#!/bin/bash
# security-incident-response.sh
echo "š”ļø SECURITY INCIDENT RESPONSE"
echo "============================="
# Step 1: Isolate (block all traffic except admin)
echo "Step 1: Enabling emergency mode..."
cp /etc/nginx/sites-available/karangrejo.desa.id /etc/nginx/sites-available/karangrejo.desa.id.backup
# Create temporary restricted access
cat > /etc/nginx/sites-available/emergency.conf << EOF
server {
listen 80 default_server;
listen 443 ssl default_server;
# Allow only admin IP
allow 192.168.1.100; # Replace with admin IP
deny all;
root /var/www/desa-karangrejo/public;
index index.php;
location / {
try_files \$uri \$uri/ /index.php?\$query_string;
}
}
EOF
nginx -t && systemctl reload nginx
# Step 2: Log incident
echo "Step 2: Logging incident..."
echo "$(date): Security incident detected and emergency mode activated" >> /var/log/security-incidents.log
# Step 3: Backup current state
echo "Step 3: Creating incident backup..."
cd /var/www/desa-karangrejo
tar -czf /tmp/incident-backup-$(date +%Y%m%d-%H%M%S).tar.gz .
# Step 4: Notify administrators
echo "Step 4: Notifying administrators..."
echo "Security incident detected at $(date). Emergency mode activated." | \
mail -s "SECURITY INCIDENT - Immediate Action Required" [email protected]
echo "Emergency response completed. Manual investigation required."
š Support Contacts
Internal Team
š§ Technical Support: [email protected]
šØāš¼ System Administrator: [email protected]
š Security Team: [email protected]
š Emergency Hotline: +62-xxx-xxxx-xxxx
External Support
š Hosting Provider: [Your hosting provider support]
š§ Laravel Community: https://laracasts.com/discuss
š Stack Overflow: https://stackoverflow.com/questions/tagged/laravel
š Documentation: https://laravel.com/docs
Escalation Matrix
Level 1: Website tidak dapat diakses (< 1 jam)
ā Restart services, check basic issues
Level 2: Masalah persisten (1-4 jam)
ā Detailed diagnosis, check logs, contact hosting
Level 3: Data corruption/Security breach (Immediate)
ā Emergency response, isolate system, contact experts
Troubleshooting yang efektif memerlukan diagnosa sistematis dan solusi bertahap š ļø