ERR_CONNECTION_REFUSED on Localhost (XAMPP, Laragon, MAMP)

ERR_CONNECTION_REFUSED on Localhost error guide banner

DIRECT ANSWER

`ERR_CONNECTION_REFUSED` on localhost means the browser cannot connect to a listening local web server. In XAMPP, Laragon, or MAMP, first confirm that Apache or Nginx is running; if it will not start, check for a port conflict on 80 or 443 and read the server error log. If the server uses a custom port such as 8080, include that port in the localhost address.

Key takeaways

  • Confirm that Apache or Nginx is running before changing project files.
  • A server that starts and immediately stops usually has a port conflict or configuration error.
  • Check ports 80 and 443 only when those are the ports your local stack is configured to use.
  • Use the error log to distinguish a bind or port problem from an invalid server configuration.
  • If the stack uses a custom port, test localhost with that port, such as localhost:8080.
  • A loaded default page confirms the connection is working; project routing problems should then be investigated separately.
Updated 2026-09-24 · Editorial review pending HTTP & Server Errors
SA

Site Administrator

What this error means & how to recognize it

  • The browser immediately displays ERR_CONNECTION_REFUSED for localhost or a local hostname.
  • XAMPP, Laragon, or MAMP shows Apache or Nginx as stopped, failed, or no longer running.
  • The server starts and then stops, sometimes with a message about a port, configuration file, or syntax error.
  • The issue appears after a restart, operating-system change, local-server installation, or configuration edit.
  • Project files exist on the computer, but the browser cannot connect to the local server.
  • A custom-port server may work at one address while plain localhost fails because the browser is using the default HTTP port.

Root causes, ordered by likelihood

  1. Apache or Nginx is not running — The local service may not have been started or may have failed during startup.
  2. Another process is using the configured port — IIS, another XAMPP/Laragon/MAMP installation, standalone Apache or Nginx, virtualization software, or another application may already be listening on port 80 or 443.
  3. The server configuration is invalid — A syntax error in httpd.conf, an Nginx configuration file, a virtual-host file, or another recently edited server file can make the service stop immediately.
  4. The browser is using the wrong port — A stack configured for port 8080 or another custom port will not normally respond to plain localhost on the default HTTP port.
  5. Firewall or antivirus software is interfering — A recent security-software change may block the local server or its network binding, although this is less common than a stopped service or port conflict.

How to fix it

1Is Apache or Nginx stopped? Start it and test the exactconfigured localhost address.2Does startup mention a port conflict? Identify theprocess using the configured port; stop or reconfigureit only with authorization.3Does startup identify a configuration file or line?Correct or revert that specific configuration change,then start the service again.4Is there no clear startup error? Check for a duplicatelocal stack and review recent firewall or antiviruschanges.5Does the default page load? The connection is fixed;troubleshoot the project, document root, or virtual hostseparately.
Diagnostic flow at a glance — full detail in the steps below.

1. Confirm the local server and address

Open the XAMPP Control Panel, Laragon, or MAMP application and check whether Apache or Nginx is marked Running. If it is stopped, select Start and record the exact message if startup fails.

Check which HTTP or HTTPS port the stack is configured to use. If it uses a custom port, test the matching address—for example, localhost:8080—rather than assuming that plain localhost is correct.

2. Identify a port conflict

If the startup message mentions a port already in use, check the relevant port. On Windows, open Command Prompt with Administrator permission if required by the environment and run these read-only commands:

text
netstat -ano | findstr :80
netstat -ano | findstr :443

Use the reported process ID to identify the owner in Task Manager. Do not terminate an unfamiliar process. If IIS owns the port and you are authorized to change the machine, disable or stop the relevant IIS service only when IIS is not needed. Otherwise, configure the local stack to use an available port and use that port in the browser.

The commands above are Windows-specific. On another operating system, use its built-in network or process tools, or the port information provided by the stack’s control panel.

3. Check the server error log

If no obvious process owns the configured port, open the Apache or Nginx error log from the local stack or its configured log directory. Look for the first specific error, especially a file path, configuration directive, and line number.

If the failure began after a configuration edit, correct or revert that change. Check httpd.conf, Nginx configuration files, virtual-host definitions, and any included files. Change one file at a time so the cause remains identifiable.

4. Check for duplicate local servers

Look for a second XAMPP, Laragon, MAMP, WAMP, standalone Apache, or Nginx installation. Two services cannot normally listen on the same address and port. Stop an unused service only if you know it is safe and have authorization, or assign separate ports to the stacks you need to keep.

5. Review security-software changes

If the server configuration is valid and no competing process owns the port, review recent firewall or antivirus changes. Use the security product’s normal settings and create an exception only when you understand the access it permits. Avoid broadly disabling protection as a first troubleshooting step.

6. Verify the repair

Wait until Apache or Nginx remains in the Running state, then open the configured localhost address again. A default server page or the project should load instead of ERR_CONNECTION_REFUSED.

If the default page loads but the project does not, the connection problem is resolved. Continue with document-root, routing, virtual-host, or application-specific troubleshooting rather than changing port settings again.

Prevention & how to verify the fix

  • Record the HTTP and HTTPS ports used by each local stack, especially when more than one stack is installed.
  • Avoid running multiple local servers on the same address and port; assign distinct ports when both are required.
  • Keep a note of changes to Apache, Nginx, and virtual-host configuration files.
  • After editing server configuration, start the service and inspect its error log before assuming the project code is broken.
  • Use the stack’s control panel to confirm that the service stays running, not merely that it starts once.
  • Before stopping a process or service, verify that it is not required by IIS, another development tool, or an unrelated application.

When to get outside help

Consult the relevant XAMPP, Laragon, or MAMP documentation or community support when the service still stops after a configuration repair, the error log identifies a directive you cannot interpret, or the process using the port cannot safely be stopped. Include the stack name, operating system, configured HTTP/HTTPS ports, exact startup message, and relevant error-log lines. If the default page loads but the application fails, seek help for the project or virtual-host configuration instead. This error is usually a local-machine issue rather than a live-site or hosting-provider outage.

Run a website check

Frequently asked questions

Why does localhost show ERR_CONNECTION_REFUSED?

The browser could not connect to a listening local web server. Apache or Nginx may be stopped, may have failed to start, or may be listening on a different port than the one used in the browser.

How can I tell whether a port conflict caused the error?

Try starting Apache or Nginx and read the startup message. If it reports that port 80, 443, or another configured port is in use, identify the owning process before stopping or reconfiguring anything.

Can another XAMPP, Laragon, or MAMP installation cause this error?

Yes. Multiple local server installations can compete for the same address and port. Keep only the required service running or assign different ports, provided the change is safe and authorized.

What should I do if Apache starts and then stops?

Open the server error log and find the first specific error. A named configuration file and line number points toward a configuration problem; a bind or port message points toward a conflict.

Does ERR_CONNECTION_REFUSED mean that my project code is broken?

Usually not. The error occurs before the browser can receive a response from the application. First confirm that the stack’s default page loads, then investigate the project’s document root, routing, or virtual host if necessary.

What if my local server uses port 8080?

Open the localhost address with the configured port, such as localhost:8080, and ensure the server, browser address, and any virtual-host configuration agree. Plain localhost normally targets the default HTTP port instead.

Further documentation

For stack-specific procedures, consult the official documentation for the local product in use—XAMPP, Laragon, or MAMP—especially its Apache/Nginx startup controls, port settings, and error-log locations. For process identification, service management, firewall rules, and port inspection, use the official documentation for the operating system. The control panel’s status message and the server’s own error log are the most useful machine-specific references.