Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Localhost running on mac.. Can I view it on my Android phone?

Running a ruby on rails project on my mac. I need to test it on my android phone. Is there a way to view my mac localhost on my android phone?

like image 635
Mark Steggles Avatar asked Jun 12 '12 22:06

Mark Steggles


People also ask

How can I access localhost on Android?

You can access your host machine with the IP address "10.0. 2.2". This has been designed in this way by the Android team. So your webserver can perfectly run at localhost and from your Android app you can access it via "http://10.0.2.2:8080".

How do I access localhost from another device?

Jump to step:Connect both devices to the same network. Find the IP address of your computer. Find the host name of your computer. Open your mobile browser and visit the IP address or host name.

How do I access locally hosted sites on my phone?

On your mobile device's browser (any will work), navigate to http://<Local IP Address>:<port number> . For example, if I was serving on localhost:8080 and my local IP address is 123.45. 67.890, on my mobile device's browser I would navigate to http://123.45.67.890:8080 . The http:// is important, don't leave it off.


1 Answers

The name "localhost" is just a loopback to your own computer. To access it on your Android, you need to find the computer's IP address.

The most general way of finding this info, which works on both Mac and Linux, is to go into the Terminal and type ifconfig. Look for either "en0" or "en1", and under that entry look for the "inet" listing. It will be something along the lines of "192.168.1.100". When you find that address, that's what you'll want to put in your browser's address bar.

(On a Mac specifically, you can go to the Sharing pane in System Preferences and it'll tell you there.)

like image 198
Chuck Avatar answered Oct 17 '22 05:10

Chuck