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
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
| Tool | Command |
|---|---|
| Vite | npm run dev -- --host, or server: { host: true } in vite.config |
| Next.js | next dev -H 0.0.0.0 |
| Astro | astro dev --host |
| PHP built-in server | php -S 0.0.0.0:8000 |
| Python | python3 -m http.server 8000 --bind 0.0.0.0 |
| Rails | bin/rails server -b 0.0.0.0 |
| Django | python 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 en0in 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, setserver.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://localhostas a secure context but nothttp://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 StoreQuestions people ask
Why can’t my iPhone open localhost?
How do I find my Mac’s IP address for this?
Do the iPhone and computer need to be on the same Wi-Fi?
Why does my page load on the phone but not update when I save?
Is it safe to run a dev server on 0.0.0.0?
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