XAMPP - Share my PC localhost on mobile hotspot to any devices

JJ D. Lordes picture JJ D. Lordes · Jul 11, 2018 · Viewed 7.4k times · Source

I wanted to try localhost in my mobile, so I can see if it is really responsive cause in the chrome there are only few selections like iPad,etc.. so My PC has a mobile hotspot. Is it possible to share my localhost to the connected devices?

Answer

RivenSkaye picture RivenSkaye · Jul 11, 2018

Why are you using your PC as mobile hotspot? Isn't there another network that both your PC and other devices can connect to and find each other on?

Either way, localhost is just a shorthand for the local loopback IP address (127.0.0.1), which is used for a computer to handle network requests to itself. Now, if the other devices can connect to the PC, then all you need to do is find out what your IP address on the local network is, if XAMPP's Apache server is listening for requests on the network and if any local Firewall isn't blocking access.

(Windows)Before you do anything else, make sure Windows IIS isn't running! It occupies the default http port (80) and is going to cause problems if it's there!

First up, figuring out your IP address:

  • (Windows)Open the commandprompt (start -> search cmd.exe or run and enter cmd) // (Linux/Unix/Mac)Open a terminal
  • (Windows)run ip-config and look for the line that specifies your IPv4 address, write it down if you have to // (Linux/Unix/Mac)run ifconfig and look for the line stating inet. Either way, this address probably looks like 192.168.X.Y

Next, check to see if Apache is listening

  • As this is often the default setting, it probably is. So grab any other device connected on the same network and open a browser
  • In the address bar type the 192.168.X.Y IP address of the PC running XAMPP
  • If you don't see an error, go to your files and enjoy!
  • If you do get an error, change the config for Apache (httpd.conf) and search for a line containing "Listen 80", if you can't find it then it's probably listening to 0.0.0.0:80 and you need to edit that line to "Listen 80" as that will allow it to listen to all addresses on the network.

Finally, you can't reach it so check if your firewall is blocking access. This is usually Windows firewall not trusting anything that doesn't carry a Microsoft label

  • Go to Control Panel > Windows Firewall > Allow a program to communicate through windows firewall > Add another program Name: http Port: 80

If it still doesn't work and you're running Windows, refer to this Stack Overflow question as you are not the first person that has trouble setting things up.