Localhost Refused to Connect? Jangan Panik, Begini Solusinya!
Saat kamu mengetik localhost di browser tapi muncul “localhost refused to connect”, artinya komputer tidak bisa berbicara dengan server lokal sendiri. Error ini paling sering muncul di XAMPP, WAMP, atau Laravel Valet karena tiga hal: service Apache mati, port 80 dipakai aplikasi lain, atau firewall memblok koneksi loopback 127.0.0.1.
Kalau dibiarkan, kamu tak bisa menjalankan PHPMyAdmin, WordPress lokal, maupun proyek Laravel. Berikut 5 langkah teknis yang sudah saya praktikkan di Windows 11, Ubuntu 22, dan macOS Ventura. Total waktu perbaikan ±7 menit.
1. Pastikan Apache Berjalan & Port-nya Tepat
Buka XAMPP Control Panel. Kolom Apache harus hijau bertuliskan Running. Kalau belum, klik Start. Jika tombol Start langsung kembali ke Stop tanpa pesan, berarti ada crash.
Cek log terakhir lewat tombol Logs → Apache (error.log). Baris (OS 10048) Only one usage of each socket address... :80 menandakan port 80 dipakai. Solusinya ganti port:
- Klik Config → Apache (httpd.conf)
- Ganti baris
Listen 80jadiListen 8080 - Simpan, restart Apache, lalu buka
http://localhost:8080
Alternatif cepat: gunakan tombol Netstat di XAMPP untuk melihat PID yang nempel di port 80. Di Windows kamu bisa End Task lewat Task Manager; di Linux pakai sudo kill -9 <PID>.
1a. Perintah Cek Apache di Linux
Untuk Debian/Ubuntu:
sudo systemctl status apache2
Keluaran aktif:
Active: active (running) since Mon 2025-07-09 07:42:15 UTC
Kalau inactive, start pakai:
sudo systemctl start apache2
1b. Menentukan Port Alternatif Secara Aman
Port 8080, 8000, atau 8888 umumnya bebas. Hindari port <1024 yang butuh hak admin. Setelah ganti port, sesuaikan juga ServerName localhost:8080 agar tidak muncul warning saat restart.
2. Bersihkan Cache DNS & HSTS Browser
Cache DNS usang bisa menyebabkan browser salah arah. Flush DNS:
- Windows: buka CMD lalu
ipconfig /flushdns - macOS:
sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder - Linux (systemd-resolved):
sudo systemd-resolve --flush-caches
Chrome kadang paksa HTTPS di localhost. Buka chrome://net-internals/#hsts, scroll ke Delete domain security policies, ketik localhost, klik Delete. Restart browser.
3. Tweak Firewall & SELinux (Windows, macOS, Linux)
Firewall bisa memblok loopback. Cukup nonaktifkan sementara untuk tes:
- Windows: Windows Security → Firewall & network protection → Private network → off
- macOS: System Settings → Network → Firewall → off
- Ubuntu (ufw):
sudo ufw disable
Ingat, segera nyalakan kembali setelah localhost bisa diakses. Untuk SELinux di CentOS, pakai:
sudo setsebool -P httpd_can_network_connect 1
Kesimpulan
Urutan ideal: (1) cek Apache hidup & port bebas, (2) ubah port kalau 80 terpakai, (3) flush DNS + clear HSTS, (4) matikan firewall sekilas, (5) baca log error bila masalah berlanjut. Dengan 5 langkah di atas saya berhasil menjalankan kembali PHPMyAdmin & Laravel localhost di bawah 5 menit.
Mulai sekarang kalau menemui localhost refused to connect kamu tinggal ingat rangkaian APD-FLC: Apache-Port-DNS-Firewall-Check. Masih buntu? Share log error-mu di kolom komentar, kita bongkar bareng.
FAQ
Tidak. Localhost adalah loopback interface PC sendiri. Agar HP lain terhubung, pakai IP LAN komputer (mis. 192.168.x.x) dan pastikan Apache listen pada 0.0.0.0.
Biasanya karena service masih listen ke port lama. Cek httpd.conf, pastikan Listen & ServerName konsisten, lalu restart Apache.
Tidak perlu. 90% kasus cukup atur port & firewall. Install ulang hanya bila file konfigurasi corrupt atau service registry Windows rusak.