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 šŸ› ļø