Home/Blog/How to Fix ‘Localhost Refused to Connect’ (XAMPP, WAMP, Docker) 2026

How to Fix ‘Localhost Refused to Connect’ (XAMPP, WAMP, Docker) 2026

Browser showing localhost refused to connect error on developer desk

You type http://localhost into the browser and instead of your project you get “localhost refused to connect” (ERR_CONNECTION_REFUSED). This localhost refused to connect fix guide starts with the blunt truth: in nearly every case, nothing is listening on that address and port. Either your local server (XAMPP, WAMP, MAMP, Laragon, Docker, or a dev server like npm run dev) is not running, or it is running on a different port than the one you typed. This 2026 guide walks through the checks in the order that finds the cause fastest.

Unlike internet errors, localhost problems are entirely on your machine: the browser asked your own computer for a web page and got silence back. That narrows the suspects to a short list — a stopped service, a port conflict, a wrong port number, or a firewall getting in the way. Work through the steps below and you will know within minutes which one it is.

What Causes “Localhost Refused to Connect”

  • Server not running: Apache/Nginx (or your dev server) is stopped or crashed — the single most common cause.
  • Wrong port: the server listens on 8080, 3000, or 5173, but you typed plain localhost (port 80).
  • Port conflict: another app (Skype, IIS, another server) grabbed port 80, so Apache failed to start.
  • Firewall or antivirus: blocking local connections to the web server process.
  • Browser cache/HSTS: stale redirects or forced-HTTPS policies sending you to the wrong scheme.
  • Docker port mapping missing: the container runs, but no host port is published to reach it.

How to Fix “Localhost Refused to Connect”: 8 Steps

Step 1: Confirm the server is actually running

Open your stack’s control panel — XAMPP Control Panel, WAMP tray icon (green = running, orange/red = problem), or your terminal where npm run dev / php artisan serve should still be active. If the process exited or the service shows stopped, start it and retry. For XAMPP, run the control panel as administrator to avoid permission failures.

Step 2: Use the exact address the tool printed

Dev servers announce their URL on startup: Local: http://localhost:5173/, Server running at http://127.0.0.1:8000, Listening on port 3000. Copy that exact address — including the port — into your browser. Typing bare localhost when the server is on :8080 will always refuse.

Step 3: Try 127.0.0.1 instead of localhost

Open http://127.0.0.1 (plus the port if needed). If this works while localhost fails, your hosts file or DNS resolver is not mapping the name correctly — use the IP form going forward, or repair the 127.0.0.1 localhost entry in your hosts file.

Local web server control panel with Apache and MySQL service start buttons

Step 4: Hunt down port conflicts

If Apache will not start in XAMPP, something owns port 80. On Windows, run as administrator: netstat -ano | findstr :80, note the PID in the last column, and match it in Task Manager → Details. Common culprits: Skype, IIS, SQL Server Reporting Services. Either stop the conflicting app or move Apache to another port.

Step 5: Change Apache’s port (XAMPP/WAMP)

Stop Apache, open C:\xampp\apache\conf\httpd.conf (XAMPP) or the equivalent in WAMP, and change Listen 80 → Listen 8080 and ServerName localhost:80 → ServerName localhost:8080. Save (as administrator), restart Apache, and browse to http://localhost:8080.

Step 6: Check firewall and antivirus

Temporarily disable your firewall/antivirus and retry. If localhost connects, add an exception for your server binary (httpd.exe, node, etc.) and re-enable protection. Also check Windows Defender’s blocked-apps list after major updates — upgrades sometimes re-block previously allowed programs.

Step 7: Clear browser data and HSTS for localhost

Chrome sometimes forces localhost to HTTPS via cached HSTS. Visit chrome://net-internals/#hsts, enter localhost under “Delete domain security policies”, and delete. Then clear site data for localhost (padlock icon → Site settings → Clear data) and retry in a private window.

Step 8: Check Docker port publishing

For Docker setups, run docker ps and inspect the PORTS column — you need a mapping like 0.0.0.0:8080->80/tcp. If the mapping is missing, your container is unreachable from Windows/macOS regardless of it running fine inside. Recreate with -p 8080:80. For broader connection failures, see our connection timed out guide.

How to Prevent Localhost Connection Refusals

  • Give each project a fixed, documented port — no more guessing which :3000 is which.
  • Set XAMPP/WAMP services to start with Windows if you develop daily.
  • Keep one local stack at a time; uninstall or disable the ones you no longer use to avoid port wars.
  • After Windows updates, re-verify firewall exceptions for your dev tools.

Conclusion

“Localhost refused to connect” is your own machine telling you nothing answered the door: start the server, use the right port, evict port squatters, and clear stale browser policies. Run the eight steps in order and your local environment will be back in minutes. For more developer-environment fixes, keep reading the KamiWeb blog.