Skip to content

Instantly share code, notes, and snippets.

@Ronin1702
Last active December 16, 2025 00:30
Show Gist options
  • Select an option

  • Save Ronin1702/8b54f8ca605de6876a0324fbac969593 to your computer and use it in GitHub Desktop.

Select an option

Save Ronin1702/8b54f8ca605de6876a0324fbac969593 to your computer and use it in GitHub Desktop.
Accessing Localhost from iPhone

Accessing Localhost from iPhone

If you are developing a web application and want to test it on your iPhone, you can access your localhost development server directly from your iPhone. Here's how to do it:

Prerequisites

  • Ensure both your development machine and iPhone are connected to the same local network (e.g., the same WiFi).

1. Find Your Local IP Address

Windows:

  1. Open the Command Prompt.
  2. Type ipconfig and press Enter.
  3. Look for the "IPv4 Address" or "IP Address" entry. This will give you your local IP address, e.g., 192.168.1.X.

Mac:

  1. Open Terminal.
  2. Type ifconfig | grep inet and press Enter.
  3. Look for an address that's not 127.0.0.1. It will typically look something like 192.168.1.X.

Linux:

  1. Open Terminal.
  2. Type hostname -I and press Enter.
  3. You'll get your local IP address.

2. Update Your Development Server Configuration

Ensure your development server binds to 0.0.0.0 (all available network interfaces) so it's accessible from other devices.

For Vite, modify the vite.config.js:

export default {
  server: {
    host: '0.0.0.0'
  }
}

Then, run your development server. It should indicate it's accessible on 0.0.0.0:3000.

3. Access from iPhone

  1. Open Safari or any browser on your iPhone.
  2. Enter the local IP address found in step 1 followed by the port number. For example:
  http://192.168.1.5:3000

Important Notes

Some development servers may have security restrictions preventing access from different devices or domains. Adjust CORS or "host check" settings if needed. This method exposes your development server to your local network. Ensure you're not exposing any sensitive data or operations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment