Logo

dev-resources.site

for different kinds of informations.

How to Preview localhost Website on Mobile Phone

Published at
5/15/2023
Categories
localhost
preview
mobile
Author
nikolalsvk
Categories
3 categories in total
localhost
open
preview
open
mobile
open
Author
10 person written this
nikolalsvk
open
How to Preview localhost Website on Mobile Phone

Scrolling a website on phone next to a computer

Photo by Maxim Ilyahov on Unsplash

Are you looking to preview your website on your mobile (or tablet) while developing it on your computer? Or vice-versa? Maybe you want to get a “real feel” of how the website works and looks directly on the device. Then, you’re in for a treat. Today, we’ll show how you can visit the website hosted on localhost directly from your mobile or tablet.

Step 1: Connect your device to the same network

If you have multiple WiFi networks, ensure your computer and device are on the same WiFi. This step is essential.

Step 2: Find your computer’s local IP address

Your computer has a public IP and a local IP address. We need a local IP address , IPv4, to be more precise. You must be asking - “How do I find my local IP address?“. Here’s how you can do it on different operating systems:

Mac OS

  1. Open System Preferences -> Network
  2. Next to the Status, you should see the IP address. It should write out - “WiFi is connected to YOUR_WIFI_NAME and has the IP address YOUR_LOCAL_IP.” See how it looks in the screenshot below:

Mac OS network settings

The local IP address is underlined in red.

Linux

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

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 3. Get the port number

If you’re running a Rails app, the port is usually 3000, and you can access your app in the http://localhost:3000.

💡 In my case, I had to bind the server to 0.0.0.0. I run a Gatsby website, so for me, it was gatsby develop --host 0.0.0.0, which runs the server that listens on the 8000 port.

Whatever way you run your server, make sure to use the PORT from http://localhost:PORT - where the server listens for incoming requests.

Step 4: Open your other device’s browser

On your phone or tablet, open your browser of choice and type in http://YOUR_LOCAL_IP:PORT - which in my case was http://192.168.1.30:8000.

If you’re running a server on http://localhost:3000, and your IP is 192.168.1.10, then you need to visit http://192.168.1.10:3000 on your mobile or tablet.

That is it

You can now browse your website directly from your other device while you develop on the computer. How neat!

Now, you can test mobile and tablet views on real devices. That is if you need to do so.

Thanks for following along, and catch you in the next one.

localhost Article's
30 articles in total
Favicon
Accessing a Laptop's Server on Port 80 from Your Phone via Wireless Debugging
Favicon
Expose Your Localhost to a Public URL
Favicon
Comprehensive Guide to Localhost IP Addresses: 127.0.0.1
Favicon
Exploring Localhost 127.0.0.1:62893: Setup and Usage Guide
Favicon
Exploring Localhost 127.0.0.1:49342: Setup and Usage Guide
Favicon
127.0.0.1:57573: Benefits, Comparisons, and Troubleshooting Guide
Favicon
Understanding Localhost Networking: A Comprehensive Guide
Favicon
Access Localhost on Mobile Within the Same Network
Favicon
Set Up Your Own Local GitLab Server | Self-hosted GitLab
Favicon
Run your Sveltekit (or any vite) localhost server with HTTPS
Favicon
Change your Sveltekit (or any vite-powered) dev server localhost port
Favicon
How to Install or Download MongoDB 7 on Windows 10/11 | Step by Step Guide for Localhost
Favicon
What is Localhost in Development Mode?
Favicon
How to share your "localhost" with the world
Favicon
Trabalhando com AWS em um ambiente localhost
Favicon
Best DX for cookies on localhost
Favicon
How to access your site in mobile phone during development
Favicon
Fix MySQL Error: Access Denied for User ‘root’@’localhost’
Favicon
Setting up an Alias for a Directory in Apache2 Server
Favicon
How can I set up SSL on localhost (https://localhost/)?
Favicon
How to test https on localhost with help of Caddy
Favicon
How To Use Visual Studio Dev Tunnels to Receive Webhooks on Localhost
Favicon
How to Preview localhost Website on Mobile Phone
Favicon
How to stop Localhost server running on multiple ports.
Favicon
Let's Run PHP On Localhost with XAMPP Server
Favicon
How to Fix the XAMPP Error “MySQL Shutdown Unexpectedly”
Favicon
Nuxt and Cloudflare, how to get SSR working (2 settings)
Favicon
How to use LocalXpose with a Localhost WordPress
Favicon
What Happens When You Visit http://localhost - A Closer Look
Favicon
Share your localhost with Cloudflare tunnels

Featured ones: