Coffee
← Blog Mac Productivity

Access Localhost From Your Phone: Mac Dev Server Guide

By FavTray ·

Written by the team behind FavTray, a Mac developer dashboard for the menu bar. We check every app we cover against its own site, docs or a hands-on test, and each post says which.

Short answer: Your phone can’t use localhost, because to the phone that means the phone. Start your dev server so it listens on the network (npm run dev -- --host for Vite), get your Mac’s IP with ipconfig getifaddr en0, and open http://THAT-IP:PORT on the phone while both are on the same Wi-Fi. Click Allow if macOS asks about incoming connections.

TL;DR

  • Listen on the network: Vite --host, Django 0.0.0.0:8000, Flask --host=0.0.0.0, Rails -b 0.0.0.0. Next.js already does.
  • Find the Mac’s IP (read-only): ipconfig getifaddr en0
  • Open on the phone: http://192.168.1.23:5173, same Wi-Fi, no VPN in the way.
  • API calls failing: your front end is calling localhost, which on the phone is the phone.
  • Need camera or service workers: plain http on an IP isn’t a secure context. Use HTTPS or a tunnel.

Why doesn’t localhost work on my phone?

Two separate things go wrong, and you usually hit both:

  1. The name. localhost and 127.0.0.1 always mean “this device”. Typed on an iPhone, they point at the iPhone. You need your Mac’s address on the local network.
  2. The bind address. Many dev servers listen on 127.0.0.1 (loopback) by default, deliberately, so nobody else on your Wi-Fi can reach them. Connections from the phone are refused even with the right IP.

You can check the second one before touching anything. Run this read-only command with your port:

lsof -nP -iTCP:5173 -sTCP:LISTEN

If the last column shows 127.0.0.1:5173 or [::1]:5173, the server is loopback-only. *:5173 means it already listens everywhere. The lsof port mac cheat sheet explains the rest of that output.

How do I make my dev server reachable from my phone?

Tell it to bind to 0.0.0.0 (all interfaces). Each framework has its own flag:

FrameworkDefaultCommand to listen on the network
Vite (React, Vue, Svelte, SvelteKit)localhostnpm run dev -- --host or npx vite --host
Next.js0.0.0.0Nothing needed; next dev -H 0.0.0.0 makes it explicit
Astrolocalhostnpx astro dev --host
Angularlocalhostng serve --host 0.0.0.0
Django127.0.0.1:8000python manage.py runserver 0.0.0.0:8000
Flask127.0.0.1:5000flask run --host=0.0.0.0
FastAPI (uvicorn)127.0.0.1:8000uvicorn main:app --host 0.0.0.0
Railslocalhost:3000bin/rails server -b 0.0.0.0
Go net/httpwhatever you pass":8080" listens everywhere, "127.0.0.1:8080" doesn’t
Dockerall interfacesAlready reachable unless you published with 127.0.0.1:

The -- in npm run dev -- --host matters: it tells npm to pass --host through to the dev server instead of keeping it. Vite’s server options document --host, and the Next.js CLI reference lists 0.0.0.0 as the default for -H.

Some frameworks also check the hostname you browse to, as a guard against DNS rebinding:

  • Django rejects unknown hosts with a 400 “DisallowedHost” error. Add your Mac’s IP (or .local name) to ALLOWED_HOSTS in development settings.
  • Next.js blocks cross-origin requests to its dev-only assets. If the page loads but hot reload or navigation breaks on the phone and the terminal mentions a blocked cross-origin request, add the address to allowedDevOrigins in next.config.js (hostname only, no http:// and no port).
  • Vite allows IP addresses by default but not other hostnames. To use your-mac.local, add it to server.allowedHosts.
  • Rails in development allows any IP address, but a .local name needs config.hosts << "your-mac.local".

How do I find my Mac’s IP address?

Pick whichever is closest:

  • Terminal (read-only): ipconfig getifaddr en0. On most Macs en0 is Wi-Fi. If it prints nothing (some desktops with Ethernet), try en1.
  • Menu bar: hold Option and click the Wi-Fi icon. The IP Address is listed under your network.
  • System Settings: Wi-Fi, click Details… next to the network you’re on, then look under TCP/IP.
  • The dev server itself: Vite and Next.js print a Network: URL when they start with network access on. Copy that.

The address can change when your router hands out a new lease. If the phone suddenly can’t connect tomorrow, check it again. A steadier option is your Mac’s Bonjour name, shown at the bottom of System Settings › General › Sharing as Local hostname (something like Akashs-MacBook-Pro.local). iPhones resolve .local names on the same network, but some frameworks need it allow-listed, as above.

How do I open it on my iPhone or Android phone?

  1. Start the dev server with its network flag from the table above.
  2. If macOS asks “Do you want the application ‘node’ to accept incoming network connections?”, click Allow. This only appears when the macOS firewall is on.
  3. Connect the phone to the same Wi-Fi network as the Mac.
  4. In the phone’s browser, type http://, your Mac’s IP, a colon and the port: http://192.168.1.23:5173. Include the http://, because some mobile browsers otherwise treat it as a search.
  5. Bookmark it, or add it to the home screen, for next time.

Why does it still not load?

SymptomLikely causeFix
Times outmacOS firewall blocking the appSystem Settings › Network › Firewall › Options…, set your runtime (node, python) to allow incoming connections
Times out on office, hotel or guest Wi-FiThe network isolates devices from each otherUse a home network or your phone’s hotspot with the Mac joined to it
Times out with VPN onVPN routing local traffic awayAllow local network access in the VPN, or disconnect while testing
”Connection refused”Server still bound to 127.0.0.1Restart it with the host flag
Page loads, data doesn’tFront end calls http://localhost:8000Use relative URLs with a dev proxy (Vite’s server.proxy), or the Mac’s IP, and bind the API to 0.0.0.0 too
400 Bad Request / blocked hostHost checkingALLOWED_HOSTS, allowedDevOrigins, server.allowedHosts (above)
Page loads, hot reload doesn’tDev assets or WebSocket blockedSame host settings; check the terminal for a warning

The “page loads, data doesn’t” row catches most people. The HTML comes from your Mac, but the JavaScript runs on the phone, so every hard-coded localhost URL in it points back at the phone.

What about HTTPS on a local IP?

Browsers give http://localhost special treatment as a secure context, so features that need one work on your Mac over plain http. http://192.168.1.23 gets no such exception. On the phone, APIs restricted to secure contexts, such as service workers and camera access, stop working, which is confusing when the same page works on your Mac.

Your options, roughly from least to most setup:

  • Test those features on the Mac and use the phone only for layout and touch. Often enough.
  • A tunnel. Tools like Cloudflare’s quick tunnels (cloudflared tunnel --url http://localhost:5173) give you a public https:// URL that forwards to your Mac. Real HTTPS, works on any network, but anyone with the URL can reach your dev server while it runs, so close it when you’re done.
  • A local certificate the phone trusts. Create a local certificate authority (for example with mkcert), issue a certificate that names the address you’ll type, install the CA’s profile on the iPhone, then turn on full trust in Settings › General › About › Certificate Trust Settings. Most work, cleanest result.
  • Self-signed HTTPS (Next.js --experimental-https, Vite’s @vitejs/plugin-basic-ssl). Quick, but the phone shows a certificate warning unless it trusts the issuer.

How do I debug the page on my iPhone?

Safari’s Web Inspector works over a cable or the same network:

  1. On the iPhone: Settings › Apps › Safari › Advanced, turn on Web Inspector.
  2. On the Mac: Safari › Settings › Advanced, turn on Show features for web developers.
  3. Open your page on the iPhone, then on the Mac choose Develop › your iPhone › the page. You get the console, network panel and element inspector for the phone’s tab.

Is it safe to expose my dev server like this?

On your own home network, generally yes. Anyone on the same network can reach the server while it listens on 0.0.0.0, and dev servers aren’t built to face strangers. So:

  • Don’t do it on café, hotel or conference Wi-Fi.
  • Don’t serve real customer data or unauthenticated admin tools this way.
  • Stop the server (Ctrl+C) when you’re done. Ports you forget about are how you end up with address already in use errors later.
  • For Docker, publish with -p 127.0.0.1:5432:5432 anything that should never leave the Mac.

Is there a quicker way to get it on my phone?

We make FavTray, so weigh our take accordingly. In FavTray’s Ports, a dev server’s detail shows a QR code that opens it on your phone when it’s reachable on the same Wi-Fi, so you skip the IP lookup and the typing. If the server is bound to localhost only, FavTray tells you which flag to start it with. It never exposes anything itself; the server’s own bind setting decides.

The phone QR is in the free tier, along with the full port list and search. Free includes 10 kills a day, and Pro is $4.99 once for unlimited. If you only test on a phone now and then, ipconfig getifaddr en0 and the table above do the same job. For freeing ports when a server gets stuck, the kill port mac guide has the commands.

Try FavTray Free

One free Mac menu bar app: notch island, ports, keep-awake, clipboard, eye rest, and Claude and Codex limits.

Download Free

Frequently Asked Questions

Why can't I open localhost on my phone?

On your phone, 'localhost' means the phone itself, not your Mac. You need your Mac's local IP address instead, such as http://192.168.1.23:5173. Even then, many dev servers only listen on 127.0.0.1 by default, which refuses outside connections. Start the server with its host flag, for example 'vite --host', so it listens on your network.

How do I find my Mac's IP address for testing on a phone?

Run 'ipconfig getifaddr en0' in Terminal, which prints the Wi-Fi address on most Macs. Or hold Option and click the Wi-Fi icon in the menu bar to see IP Address, or open System Settings › Wi-Fi and click Details next to your network. Vite and Next.js also print a Network URL when they start.

What does 0.0.0.0 mean for a dev server?

Binding to 0.0.0.0 tells the server to accept connections on every network interface: loopback, Wi-Fi and Ethernet. Binding to 127.0.0.1 or localhost accepts connections from the same Mac only. You don't type 0.0.0.0 into the phone's browser; you type your Mac's real IP address and the port.

Is it safe to run my dev server on 0.0.0.0?

On your home network it's usually fine, but anyone on the same network can reach the server while it runs, and dev servers aren't hardened. Avoid it on café, hotel or conference Wi-Fi, never expose admin panels or real data this way, and stop the server with Ctrl+C when you're done testing.

Why does my site load on the phone but the API calls fail?

Your front end probably calls http://localhost:8000 for its API. On the phone, localhost is the phone, so the request goes nowhere. Use relative URLs and your dev server's proxy (Vite's server.proxy, for example), or point the API base URL at your Mac's IP, and make sure the API server also listens on 0.0.0.0.

Can I test camera or service workers on my phone over a local IP?

Not over plain http. Browsers treat http://localhost as a secure context, but http://192.168.x.x is not one, so features like service workers and camera access are blocked. Use HTTPS with a certificate your phone trusts, or a tunnel that gives you an https URL, for features that need a secure context.