ViewPortal
Features Multi-view Guides FAQ
Download
Home / Guides / Localhost on iPhone
Local development

How to open localhost on your iPhone

Typing localhost:5173 into Safari on your phone fails because the phone looks for a server on itself. The fix takes two minutes: make the dev server listen on your network, then use your computer’s address.

Updated 7 November 2026

Short answerStart your dev server so it listens on your network (for Vite, npm run dev -- --host), find your computer’s local IP address, and open http://<that-ip>:<port> on the iPhone while both are on the same Wi-Fi. Away from home, install Tailscale on both and use your computer’s Tailscale name instead.

Why localhost doesn’t work on the phone

localhost always means “this device”. On your laptop it reaches the dev server; on your iPhone it reaches the iPhone, where nothing is running. The answer that has helped people since the question was first asked on Stack Overflow in 2010 is the same today: use your computer’s address on the local network instead.

There is usually a second problem. Many dev servers listen only on 127.0.0.1, which accepts connections from the same machine and nothing else, so even the right address is refused until you tell the server to listen on all interfaces.

Step 1: make the dev server listen on your network

ToolCommand
Vitenpm run dev -- --host, or server: { host: true } in vite.config
Next.jsnext dev -H 0.0.0.0
Astroastro dev --host
PHP built-in serverphp -S 0.0.0.0:8000
Pythonpython3 -m http.server 8000 --bind 0.0.0.0
Railsbin/rails server -b 0.0.0.0
Djangopython manage.py runserver 0.0.0.0:8000

Vite prints a “Network” URL when it is listening correctly; that is the address to use. Listening on 0.0.0.0 exposes the server to everyone on the same network, so don’t do it on café or office Wi-Fi with anything sensitive running.

Step 2: find your computer’s address and open it

  • Mac: ipconfig getifaddr en0 in Terminal (Wi-Fi on most Macs), or System Settings > Wi-Fi > Details.
  • Windows: ipconfig, then the IPv4 address of your Wi-Fi adapter.
  • Linux: hostname -I.

On the iPhone, type the full address including the scheme and port, for example http://192.168.1.23:5173. Leave off http:// and Safari may search for it instead.

When it still won’t load

  • Different networks. The phone is on mobile data, a guest network or a mesh node with client isolation. Turn Wi-Fi off and on, and check both devices show the same network name.
  • The computer’s firewall. macOS asks whether to allow incoming connections the first time a new server starts; if you clicked Deny, allow it in System Settings > Network > Firewall. On Windows, allow the port for private networks.
  • The page loads, but scripts or styles don’t. Hot reload or assets are still pointing at localhost. In Vite, set server.hmr.host; in other tools, use relative URLs or the network address in your config.
  • “Blocked request” or “Invalid Host header”. Newer Vite versions reject unknown host names. Add the name you’re using to server.allowedHosts.
  • Features that need HTTPS. Browsers treat http://localhost as a secure context but not http://192.168.1.23, so service workers, the camera, the clipboard and some sign-in flows fail over a plain LAN address. Use Tailscale Serve (below) or a locally trusted certificate.
  • An app was refused local network access. Since iOS 14 apps must ask before reaching devices on your network. If you tapped Don’t Allow, turn it back on under Settings > Privacy & Security > Local Network.

Away from home: Tailscale

Tailscale puts your computer and phone on a private network that works over any connection, so the phone can reach your dev server from a train or another country. Install it on both devices and sign in to the same account. With MagicDNS on, open http://<computer-name>:5173 (the server still needs to listen on all interfaces).

For HTTPS without touching the server’s binding, run tailscale serve on the computer, for example tailscale serve --bg 5173, and open the https://….ts.net address it prints. Serve stays inside your tailnet. Tailscale Funnel and tunnels such as ngrok publish the server to the whole internet, which is rarely what you want for work in progress.

To check it really works away from home, turn off Wi-Fi on the phone and load the address over mobile data.

Seeing your dev server at every size

Safari shows your dev server at your phone’s own width. ViewPortal loads the same LAN, Tailscale or localhost address (in the iOS Simulator, localhost reaches your Mac directly) and lays it out at true iPhone, iPad and Mac viewport sizes, so you can check the desktop layout of a change from your phone. On an iPad, or an iPhone in landscape, multi-view shows phone, tablet and desktop side by side.

ViewPortal asks for local network access only so it can reach your own dev servers. Your URLs and favourites stay on the device and nothing is sent to us. It is £4.99 once, with no subscription.

ViewPortal on the App Store

Questions people ask

Why can’t my iPhone open localhost?
Because localhost on the iPhone means the iPhone itself. Use your computer’s local IP address and port instead, and make sure the dev server is listening on all interfaces rather than only 127.0.0.1.
How do I find my Mac’s IP address for this?
Run ipconfig getifaddr en0 in Terminal, or open System Settings, Wi-Fi, then Details next to your network.
Do the iPhone and computer need to be on the same Wi-Fi?
Yes, for a LAN address. If they can’t be, use Tailscale on both devices, or a tunnel if you’re happy for the server to be publicly reachable.
Why does my page load on the phone but not update when I save?
The hot-reload connection is still pointing at localhost. Set the HMR host to your network address (server.hmr.host in Vite) or check your tool’s network settings.
Is it safe to run a dev server on 0.0.0.0?
On your home network, usually. It makes the server reachable by every device on that network, so avoid it on shared Wi-Fi, or use Tailscale Serve so only your own devices can connect.

Sources and threads

  • Stack Overflow: How do you access a website running on localhost from iPhone browser
  • Vite discussions: How to expose ‘host’ for external device display? (#3396)
  • Laracasts: localhost not accessible from mobile
  • Vite docs: server.host, server.allowedHosts and server.hmr
  • Tailscale docs: Tailscale Serve
  • MDN: Secure contexts

More guides

  • How to inspect element on iPhone
  • iPhone Duo viewport size: what Safari gives your page
  • All responsive testing guides
ViewPortal

See your site on every device — true iPhone, iPad and Mac viewports, straight from your phone.

Download on the App Store

Product

Features Multi-view How it works Guides FAQ

Company

Privacy Terms of Use
© 2026 Flavr Web Dev Ltd. All rights reserved. Flavr Web Dev Ltd is registered in England & Wales (Company No. 14994358). Registered office: 161 Cicero Crescent, Milton Keynes, Buckinghamshire, MK11 4DR.