Pemecahan Masalah

Panduan mengatasi masalah umum pada server ujian.

Service Tidak Jalan

Nginx gagal start

# Cek error
systemctl status nginx
nginx -t

# Error umum: "port already in use"
lsof -i :80
lsof -i :443
# Kill proses yang menggunakan port tersebut

# Error umum: "SSL certificate not found"
ls -la /etc/ssl/ujian/
# Pastikan file ujian.crt dan ujian.key ada dan readable

PHP-FPM gagal start

# Cek error
systemctl status php8.3-fpm
journalctl -u php8.3-fpm --no-pager -n 50

# Error umum: "pool ujian cannot get uid"
id www-data
# Jika user tidak ada: apt install nginx (creates www-data)

# Error umum: "unable to bind listening socket"
ls -la /run/php/
# Pastikan direktori /run/php/ ada
mkdir -p /run/php && chown www-data:www-data /run/php

MariaDB gagal start

# Cek error
systemctl status mariadb
journalctl -u mariadb --no-pager -n 50

# Error umum: disk penuh
df -h /var/lib/mysql/
# Bersihkan disk atau expand partition

# Error umum: InnoDB corruption
# JANGAN hapus ib_logfile* sembarangan
# Backup dulu, lalu:
examtool backup-db

Memcached gagal start

systemctl status memcached
# Biasanya masalah port conflict atau RAM tidak cukup
free -m

PHP runtime extension error

Jika muncul error terkait PHP extension yang tidak ter-load:

# Restart PHP-FPM
systemctl restart php8.3-fpm

# Cek extension loaded
php -m

# Cek file extension config
ls -la /etc/php/8.3/fpm/conf.d/

Masalah Koneksi

Tidak bisa akses dari browser

  1. Cek DNS: nslookup demo.ujiancbt.online
  2. Cek firewall: ufw status
  3. Cek nginx: systemctl status nginx
  4. Cek SSL: openssl s_client -connect demo.ujiancbt.online:443
  5. Cek log: tail -20 /var/log/nginx/ujian-error.log

ERR_CONNECTION_REFUSED

  • Port 443 (HTTPS) atau port 80 (HTTP-only) tidak dibuka di firewall
  • Nginx tidak running
  • Cek: ufw status lalu ufw allow 443/tcp atau ufw allow 80/tcp sesuai mode, kemudian systemctl restart nginx

ERR_SSL_PROTOCOL_ERROR

  • Certificate dan key tidak match
  • Certificate expired
  • Cek: openssl x509 -in /etc/ssl/ujian/ujian.crt -noout -dates

502 Bad Gateway

  • PHP-FPM tidak running
  • Socket file missing
  • Nginx user mismatch (harus www-data, bukan nginx)
  • Cek:
    systemctl restart php8.3-fpm
    ls -la /run/php/php8.3-fpm-ujian.sock
    grep "^user" /etc/nginx/nginx.conf
    

504 Gateway Timeout

  • PHP script timeout (query berat)
  • Cek slow query: tail -20 /var/log/mysql/slow-query.log
  • Tambah timeout sementara di nginx config

Masalah Database

Koneksi database gagal

# Test login manual
mysql -u usr_kedokteran -p cbt_kedokteran

# Cek MariaDB running
systemctl status mariadb

# Cek socket
ls -la /run/mysqld/mysqld.sock

# Reconfigure jika password bermasalah
examtool reconfigure

Database lambat

# Cek slow queries
tail -50 /var/log/mysql/slow-query.log

# Cek table lock
mysql -e "SHOW PROCESSLIST;"

# Cek ukuran database
mysql -e "SELECT table_schema, ROUND(SUM(data_length+index_length)/1024/1024,2) AS 'Size (MB)' FROM information_schema.tables GROUP BY table_schema;"

Backup/Restore

# Backup (default ke /root/backup_db/)
examtool backup-db

# Backup ke path lain
examtool backup-db --path=/path/to/backup

# Restore
examtool restore-db --file=/root/backup_db/backup_db_ujian_20260101_120000.sql.gz

Masalah Performa

Server lambat saat ujian

  1. Cek resource: examtool status
  2. Cek RAM: free -m — jika swap terpakai banyak, RAM kurang
  3. Cek CPU: top — cek proses yang paling banyak makan CPU
  4. Cek disk I/O: iostat -x 1 5
  5. Cek koneksi: ss -s — berapa total koneksi aktif

OOM Killer

Jika server tiba-tiba mati/restart:

dmesg | grep -i "oom\|out of memory"
journalctl -k | grep -i oom

Solusi:

  • Kurangi jumlah client di konfigurasi
  • Tambah RAM server
  • Atau switch ke tier yang lebih kecil

Memcached tidak efektif

# Cek hit ratio
echo "stats" | nc localhost 11211 | grep -E "get_hits|get_misses"
# Hit ratio < 80% → cek konfigurasi cache di aplikasi

Masalah SSL

Catatan: Section ini hanya relevan untuk instalasi dengan HTTPS. Jika menggunakan mode HTTP-only (di belakang proxy), SSL dikelola oleh reverse proxy di depannya.

Certificate expired

# Cek expiry
openssl x509 -in /etc/ssl/ujian/ujian.crt -noout -dates

# Ganti certificate
cp /path/to/new.crt /etc/ssl/ujian/ujian.crt
cp /path/to/new.key /etc/ssl/ujian/ujian.key
nginx -t && systemctl reload nginx

Certificate chain tidak lengkap

Browser menunjukkan "Not Secure" meski certificate valid:

# Gabungkan certificate dengan chain
cat ujian.crt intermediate.crt > ujian-fullchain.crt
cp ujian-fullchain.crt /etc/ssl/ujian/ujian.crt
systemctl reload nginx

Masalah Fail2ban

IP admin ter-ban

# Cek IP yang di-ban
fail2ban-client status nginx-req-limit

# Unban IP
fail2ban-client set nginx-req-limit unbanip 192.168.1.100

# Whitelist IP di jail config
# Tambahkan ke ignoreip di /etc/fail2ban/jail.d/examtool.conf

Terlalu banyak false positive

Edit /etc/fail2ban/jail.d/examtool.conf:

  • Naikkan maxretry
  • Turunkan bantime
  • Tambahkan IP range ke ignoreip

Kemudian: systemctl restart fail2ban

Masalah Update & Portal

Self-update gagal

# Cek koneksi ke portal
curl -s https://kb.ujiancbt.online/api/version

# Download manual jika self-update gagal
curl -fsSL https://kb.ujiancbt.online/download/examtool -o /usr/local/bin/examtool
chmod +x /usr/local/bin/examtool

Database import gagal

# Cek koneksi ke API database (gunakan Bearer prefix)
curl -s -H "Authorization: Bearer TOKEN_ANDA" https://kb.ujiancbt.online/api/database

# Cek 7z tersedia
which 7z || apt install -y p7zip-full

# Cek checksum tersimpan
grep DB_CHECKSUM /etc/examtool.conf

Auto-check update timeout

Auto-check saat startup memiliki timeout 5 detik. Jika portal tidak tersedia (offline/DNS gagal), perintah tetap jalan normal tanpa notifikasi update. Ini bukan error.

Log Aplikasi

Log error aplikasi (CodeIgniter) tersimpan per hari di:

/var/www/ujian/application/logs/log-YYYY-MM-DD.php

Contoh untuk melihat 100 baris terakhir:

tail -n100 /var/www/ujian/application/logs/log-$(date +%Y-%m-%d).php

Atau cek log hari tertentu:

tail -n100 /var/www/ujian/application/logs/log-2026-07-02.php

Yang perlu diperhatikan:

  • ERROR — masalah serius (query gagal, file tidak ditemukan, dll)
  • INFO — aktivitas normal (login, submit jawaban)
  • Jika folder logs/ kosong, cek permission: chown -R www-data:www-data /var/www/ujian/application/logs/

Command Diagnostik

Kumpulan command untuk troubleshooting cepat:

# Status lengkap
examtool status

# Semua log error nginx (1 jam terakhir)
find /var/log/nginx/ -name "*error*" -mmin -60 -exec tail -20 {} \;

# Koneksi aktif
ss -tuanp | grep -E ":80|:443" | wc -l

# Disk usage
du -sh /var/www/* /var/lib/mysql/ /var/log/

# Proses PHP aktif
ps aux | grep php-fpm | grep -v grep | wc -l

# Restart semua service
systemctl restart nginx php8.3-fpm mariadb memcached