Locahl
Buy Locahl
localhostmacOStroubleshootinglocal developmentlocal server

Localhost Not Working on Mac: 7 Fixes

Localhost refuses to load on your Mac? Here are 7 tested solutions: server check, hosts file, firewall, blocked ports. Step-by-step troubleshooting guide.

L

Locahl Team

Β·Updated Β·7 min read

You start your development server, open localhost:3000 in your browser, and... nothing. "This site can't be reached", "ERR_CONNECTION_REFUSED", or an endless loading page. Frustrating, isn't it?

Why is localhost not working on Mac?

If localhost isn't working on Mac, the server is usually not running, is listening on a different port, or the `127.0.0.1 localhost` line is missing from /etc/hosts. Confirm the server is up with `curl -I http://localhost:3000`, check the port it binds to, restore the localhost entry, then flush DNS.

This guide will help you diagnose and fix localhost problems on Mac, step by step.

Quick Diagnosis

Before diving into solutions, let's identify the type of problem:

SymptomLikely CauseSolution
ERR_CONNECTION_REFUSEDServer not started or wrong portSolution #1
Page loads foreverFirewall or timeoutSolution #3
localhost OK but domain.local notHosts fileSolution #4
Worked yesterday, not todayDNS cache or zombie processSolution #2, #5

Solution #1: Check that the server is running

It seems obvious, but this is the most common cause.

Check your terminal

Does your server display "Listening on port 3000" or similar?

BASH
# Example with npm
npm run dev

# Expected output
> ready - started server on 0.0.0.0:3000

Check if a process is listening

BASH
lsof -i :3000

If nothing appears, no process is listening on that port.

Check the correct port

Make sure you're accessing the right port in your browser. If your server says "port 8080", don't go to localhost:3000.

Solution #2: Free up an occupied port

If you see "Port 3000 already in use", another process is blocking the port.

Identify the process

BASH
lsof -i :3000

Result:

COMMAND   PID   USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
node    12345  user   23u  IPv4  0x1234      0t0  TCP *:3000 (LISTEN)

Kill the process

BASH
kill -9 12345

Or to kill all processes on a port:

BASH
lsof -ti :3000 | xargs kill -9

Solution #3: Check the firewall

macOS firewall or security applications can block local connections.

macOS Firewall

1. Open System Settings > Network > Firewall 2. Click Options... 3. Make sure your application (Node, Python, etc.) is allowed

Third-party applications

Apps like Little Snitch, Lulu, or certain antiviruses can block localhost. Check their rules.

Quick test

Temporarily disable the firewall to test:

BASH
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate off

Don't forget to re-enable it afterwards:

BASH
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate on

Solution #4: Check the hosts file

If localhost doesn't resolve to 127.0.0.1, the problem is in the hosts file.

Check the content

BASH
cat /etc/hosts

You should see:

127.0.0.1       localhost
::1             localhost

Repair if necessary

If these lines are missing:

BASH
sudo nano /etc/hosts

Add:

127.0.0.1       localhost
::1             localhost

Save (Ctrl+O, Enter, Ctrl+X) then flush the DNS cache.

Sources and further reading

Also readFlush DNS Mac: Commands by macOS Version

Solution #5: Flush DNS cache

A corrupted DNS cache can prevent localhost from working.

BASH
sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder

Solution #6: Check the listening address

Some servers listen on 127.0.0.1 only, others on 0.0.0.0.

Important difference

  • 127.0.0.1: Accessible only from your machine
  • 0.0.0.0: Accessible from any interface (useful for Docker, VM)

Force the address in your server

JAVASCRIPT
// Node.js / Express
app.listen(3000, '0.0.0.0', () => {
    console.log('Server running');
});
PYTHON
# Python / Flask
app.run(host='0.0.0.0', port=3000)

Solution #7: Tool-specific problems

Node.js / npm

BASH
# Clean npm cache
npm cache clean --force

# Delete node_modules and reinstall
rm -rf node_modules package-lock.json
npm install

Docker

BASH
# Check that Docker Desktop is running
docker ps

# Restart Docker if necessary
killall Docker && open /Applications/Docker.app

MAMP / XAMPP

1. Check that Apache/Nginx is running (green light) 2. Check the port in preferences (80 vs 8888)

Test with 127.0.0.1 vs localhost

If localhost fails but http://127.0.0.1:3000 works, the problem is in DNS resolution, not your server.

BASH
# Test localhost
curl -I http://localhost:3000

# Test direct IP
curl -I http://127.0.0.1:3000

Use custom local domains

Rather than localhost, you can use domains like myproject.test for more clarity.

Also readHow to edit the hosts file on Mac

Framework-specific checks

Different tools fail in slightly different ways.

Next.js

Check that the dev server started on the port you are opening:

BASH
npm run dev
lsof -i :3000
curl -I http://localhost:3000

If you need to test a custom hostname, add it to /etc/hosts:

TEXT
127.0.0.1 myapp.test
::1       myapp.test

Then open http://myapp.test:3000. If the project uses secure cookies, OAuth or service workers, configure HTTPS with mkcert.

Vite

Vite may reject custom hostnames unless you allow them. If localhost works but myapp.test fails, check the Vite server host configuration.

JAVASCRIPT
export default {
  server: {
    host: '0.0.0.0',
    port: 5173
  }
}

Docker

Docker adds two more layers: container ports and host ports.

BASH
docker ps
docker compose ps
curl -I http://localhost:8080

If the container exposes port 80 but maps it to host port 8080, localhost:80 will fail while localhost:8080 works.

MAMP

MAMP often uses port 8888 instead of 80. Check the MAMP preferences before assuming the server is down.

Localhost vs custom domain

localhost is good for quick testing, but custom domains are better for serious projects.

Use localhost when:

  • You are testing a single app.
  • No cookies depend on a domain.
  • No OAuth redirect uses a custom host.
  • You do not need subdomains.

Use .test domains when:

  • You need api.myapp.test and admin.myapp.test.
  • You test secure cookies.
  • You mirror production hostname structure.
  • You work with multiple client projects.

Avoid .local on Mac because Bonjour can intercept it and make resolution slower or inconsistent.

Debug with a clean sequence

When you are stuck, run this exact sequence:

BASH
# 1. Confirm the hosts mapping
dscacheutil -q host -a name localhost

# 2. Confirm the port
lsof -i :3000

# 3. Test direct IP
curl -I http://127.0.0.1:3000

# 4. Test localhost
curl -I http://localhost:3000

# 5. Flush DNS
sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder

If Chrome still fails after Terminal tests pass, clear Chrome DNS cache:

Also readClear Chrome DNS cache on Mac

Prevent future problems

1. Use different ports per project (3000, 3001, 8000, etc.) 2. Stop servers properly (Ctrl+C) instead of closing the terminal 3. Use a manager like Locahl to avoid hosts file conflicts 4. Prefer .test domains for client and project work 5. Document ports in each project README 6. Use HTTPS locally for auth-heavy apps

Conclusion

Localhost problems on Mac usually have simple causes: server not started, port occupied, or stale DNS cache. By following this guide methodically, you should resolve 99% of cases.

If the problem persists, check your application logs and make sure your development environment is properly configured.

Share this article
Available on Windows, macOS & Linux

Ready to simplify your workflow?

Stop wasting time with the terminal. Locahl lets you manage your hosts file in a few clicks, with automatic validation and no risk of errors.

  • Intuitive visual interface
  • Automatic DNS flush
  • Multi-environment management
  • Automatic backups
  • JSON Import/Export
Buy Locahl β€” $5.99One-time payment, no subscription

Reader Reviews

4.7β˜…(3 reviews)
James M.
β˜…β˜…β˜…β˜…β˜…

"Solution #3 (firewall) was my issue. 2 hours of debugging solved in 5 minutes thanks to this article."

September 12, 2025

Claire D.
β˜…β˜…β˜…β˜…β˜…

"Very comprehensive! The diagnostic table at the beginning helped me quickly identify the cause."

November 28, 2025

Hugo P.
β˜…β˜…β˜…β˜…β˜…

"Good troubleshooting article. Would have liked more details on Docker but otherwise perfect."

January 5, 2026

Frequently Asked Questions

Why isn't localhost working on my Mac?

The most common causes are: server not started, port already in use, firewall blocking, corrupted hosts file, or stale DNS cache.

How do I check if a server is running on localhost?

Use the command 'lsof -i :PORT' (e.g., lsof -i :3000) to see if a process is listening on the desired port.

Are localhost and 127.0.0.1 the same?

Technically yes, but localhost goes through DNS resolution (hosts file) while 127.0.0.1 is a direct IP. If localhost fails but 127.0.0.1 works, the problem is in your hosts file.

How do I free up an occupied port on Mac?

Identify the process with 'lsof -i :PORT', then kill it with 'kill -9 PID'. Example: kill -9 12345.

Can Mac firewall block localhost?

Yes, if the firewall is in strict mode or if a third-party security application blocks local connections. Check in System Settings > Network > Firewall.

Related Articles

4 min read
localhosttroubleshootingERR_CONNECTION_REFUSED

Localhost Refused to Connect: How to Fix It

Fix "localhost refused to connect" (ERR_CONNECTION_REFUSED) in Chrome, on Windows, Mac, XAMPP and VS Code: check the server, the port, IPv6 vs IPv4, hosts file and firewall.

L

Locahl Team

Developer tools team

4 min read
localhostsubdomainslocal development

How to Use Subdomains on localhost for Local Development

Use subdomains on localhost: the free *.localhost trick browsers resolve automatically, fixed subdomains via the hosts file, and wildcard subdomains with dnsmasq on Mac and Linux.

L

Locahl Team

Developer tools team

3 min read
localhosttroubleshootingERR_CONNECTION_REFUSED

Fix "This site can’t be reached" on localhost

Fix "This site can’t be reached" / ERR_CONNECTION_REFUSED on localhost: check the server is running, the right port, IPv6 vs IPv4, the hosts file and firewall.

L

Locahl Team

Developer tools team

5 min read
mkcertHTTPSSSL

Fix mkcert NET::ERR_CERT_AUTHORITY_INVALID

Fix NET::ERR_CERT_AUTHORITY_INVALID with mkcert on Mac by reinstalling the local CA, regenerating certificates and checking hostnames.

L

Locahl Team

Developer tools team

10 min read
hosts filetroubleshootingmacOS

Hosts File Not Working on Mac: Fix Guide

Your hosts file changes not taking effect? Learn how to fix DNS cache issues, browser cache, file permissions, syntax errors, and encoding problems on macOS.

L

Locahl Team