How to Run Localhost on Your Mobile Phone - A Step-by-Step Guide

How to Run Localhost on Your Mobile Phone - A Step-by-Step Guide

Running localhost on your mobile phone can be a valuable tool for developers and tech enthusiasts alike. With localhost, you can test and run applications and websites on your mobile device, without the need for an external server. This of course is a substitute for running the dev-tools mobile emulator provided by chrome, firefox, or other browsers. As there’s nothing that will perfectly imitate an actual mobile browser better than the mobile device itself. This helps in catching mobile-specific bugs before they surface as a problem for users.

In this article, we will provide a step-by-step guide on how to run a localhost on your mobile phone, both for Android and iOS devices.

Step 1: Connect your devices to the same network

This is probably the easiest step, all you have to do is make sure your computer is connected to the same wifi network as your mobile devices.

Step 2: Serve your app to Localhost and get the Port

On your computer/laptop, run your app as you usually do and get the localhost address, it is usually in the form localhost:<port>

localhost sample image

For instance, the port from the image above is 9999.

Step 3: Find your computer's Local IP Address

There are different ways to find the IP address on your machine, to find out the IP address of your computer:

For Mac:

  1. Open System Preferences -> Network

  2. Next to the Status, you should see the IP address. It should write out - “WiFi is connected to WIFI_NAME and has the IP address YOUR_IP.” See how it looks in the screenshot below:

    Mac OS Network Tab

Take note of that address, also, bear in mind that It’s common for your Local IP Address to change automatically when your device or other devices connect/disconnect from the network.

For Linux:
Run in your terminal hostname -I. Or, run ifconfig | grep "inet " | grep -v 127.0.0.1

For Windows:

  1. Select Start > Settings > Network & internet > Wi-Fi and then select the Wi-Fi network you’re connected to.

  2. Under Properties, look for your IP address listed next to IPv4 address.

Great, now that we got our computer’s local IP address, we need to run our app.

Step 4: View the app on your phone

On your mobile device’s browser, you can now navigate to http://<Local IP Address>:<port number>. For example, If your application is running on localhost:9999 and your IP address is like 172.32.44.160, then on mobile, we navigate to 172.32.44.160:9999

In conclusion, running localhost on your mobile phone is a useful tool for developers and tech enthusiasts. By following these six simple steps, you can easily set up localhost on your mobile device, and test and run applications and websites right on your phone.