Fix “localhost refused to connect” After Installing XAMPP / WAMP
You install XAMPP or WAMP, open your browser, type http://localhost and instead of the dashboard you see: localhost refused to connect , This site cant be reached Very annoying, especially on a fresh install. This error usually means one of three things:
- Apache is not running.
- Apache is running on a different port.
localhostis not pointing correctly to127.0.0.1.
Lets walk through real fixes that you can try one by one.
1. Make sure Apache is actually running
XAMPP
- Open the XAMPP Control Panel.
- Look at the Apache row.
- If it is not green, click the Start button.
- If it turns green but stops again instantly, there is usually a port conflict. Go to the next section.
WAMP
- Look at the WAMP icon in the system tray:
- Red: nothing is running.
- Orange: some services are running.
- Green: everything is running.
- Left click the icon and choose Start All Services.
After starting Apache, try:
http://localhost/
If it still says “refused to connect”, continue.
2. Check for port conflicts (Apache vs another program)
By default Apache uses port 80 (HTTP) and 443 (HTTPS). If any other program is already using port 80, Apache cannot start correctly and localhost will fail.
Common culprits:
- IIS (Internet Information Services)
- Skype / Zoom
- VMware / VirtualBox services
- Other local web servers
- Some VPN or security tools
Check which program is using port 80 (Windows)
Open Command Prompt as Administrator and run:
netstat -ano | findstr :80
Look at the last column (PID), then open Task Manager → Details tab → find that PID to see which program it is. You have two options:
- Stop or uninstall the conflicting program.
- Change Apaches port in XAMPP / WAMP.
Most people choose option 2.
3. Change Apache port in XAMPP
If port 80 is blocked and you do not want to stop the other service, change Apache to use another port like 8080.
- Open XAMPP Control Panel.
- Next to Apache, click Config → Apache (httpd.conf).
- Search for this line:
Listen 80Change it to:Listen 8080 - Search for:
ServerName localhost:80Change it to:ServerName localhost:8080 - Save the file.
If you also use SSL, edit httpd-ssl.conf:
- XAMPP Control Panel → Apache → Config → httpd-ssl.conf.
- Find:
Listen 443and change to something like:Listen 8443 - Find:
<VirtualHost _default_:443>and change to:<VirtualHost _default_:8443> - Save and restart Apache from the XAMPP Control Panel.
Now open:
http://localhost:8080/
If the dashboard opens, the port conflict was the problem. Remember to always include :8080 in the URL for that project or create a virtual host.
4. Change Apache port in WAMP
For WAMP, the process is similar.
- Left click on the WAMP icon.
- Go to Apache → httpd.conf.
- Find:
Listen 80Change to:Listen 8080 - Also search for:
ServerName localhost:80Change to:ServerName localhost:8080 - Save the file.
- Left click WAMP icon → Restart All Services.
Now open:
http://localhost:8080/
You should see the WAMP homepage.
5. Check the hosts file (localhost mapping)
Even if Apache is running, localhost must resolve to 127.0.0.1. If the hosts file is modified, you might get connection errors.
- Open Notepad as Administrator.
- File → Open and browse to:
C:\Windows\System32\drivers\etc\hostsChange file type to “All Files” to see it. - Make sure you have this line and that it is not commented:
127.0.0.1 localhost - Remove any weird extra mappings for localhost.
- Save the file.
Test again in your browser.
6. Use the correct URL (especially after port change)
If you changed the Apache port to 8080, the correct URLs are:
- XAMPP dashboard:
http://localhost:8080/ - WAMP homepage:
http://localhost:8080/ - Project folder:
http://localhost:8080/myproject/
If you still type only http://localhost/ while Apache is listening on 8080, you will continue to see “refused to connect”.
7. Allow Apache through Windows Firewall
Sometimes the server is running but your firewall blocks incoming connections.
- Open Control Panel → System and Security → Windows Defender Firewall.
- Click Allow an app or feature through Windows Defender Firewall.
- Look for Apache HTTP Server or httpd.exe.
- Make sure Private (and Public if you need) is checked.
- If you do not see it, click Allow another app and browse to:
- For XAMPP:
C:\xampp\apache\bin\httpd.exe - For WAMP:
C:\wamp64\bin\apache\apacheX.Y.Z\bin\httpd.exe
- For XAMPP:
- Save and test
http://localhostagain.
8. Run panels as Administrator
Sometimes Apache cannot bind to a port because it lacks permission.
- Right click XAMPP Control Panel → Run as administrator.
- Or for WAMP, right click the shortcut and choose Run as administrator.
Then start Apache again.
9. Clear browser cache and check with another browser
It sounds silly, but cached redirects or HSTS rules can cause localhost to misbehave.
- Clear cache for
http://localhost. - Try another browser (Chrome, Firefox, Edge).
- Also try
http://127.0.0.1/directly.
If 127.0.0.1 works but localhost does not, it is almost always a hosts file or DNS issue.
10. Quick checklist
Here is a summary you can keep for later:
- Is Apache running in XAMPP / WAMP?
- Is another program using port 80 or 443?
- Did you set a custom port and forget to add it in the browser URL?
- Does
127.0.0.1resolve correctly in the hosts file? - Is the Windows Firewall or antivirus blocking Apache?
- Are you running the control panel as Administrator?
Usually, fixing one of these points will solve the “localhost refused to connect” error on a new XAMPP or WAMP installation.