Search code examples
serverxampplocalhost

What can be the reason I cannot access local host from other devices in the network?


I have made a local host with one pc and I am trying to access it through other devices. The problem is the server is accessable only in the host. What should I do to make connection possible through other devices in the network. I use Xampp for local host and IP address of the host to make connection through browser.


Solution

  • localhost itself means that the host is located on the local computer so it cannot be accessed directly from an external computer. when you type localhost on the browser your server recognizes it and redirects it to a local port or ip address according to the address that is given. localhost is a special hostname that almost always resolves to 127.0.0.1. If you ask someone else to connect to http://localhost they'll be connecting to their computer instead or yours.

    so in order to reach this computer you need to find what your local network's IP of that computer is. Then other people can access to your site by that IP.

    If devices are in the same network:

    You can find your local network's IP by go to Command Prompt or press Windows + R then type in ipconfig or ipconfig /all. It will give out some information and your local IP should look like 192.168.1.x.

    You'll also need to make sure any firewalls you may have configured allow traffic on port 80 to connect to the XAMP server

    These are the steps to follow when you want your PHP application to be accessed from a LAN server (not on web)

    1. Get the internal IP or Static IP of the server (Ex: 192.168.1.193)
    2. Open XAMPP>apache>conf>httpd.conf file in notepad
    3. Search for Listen 80
    4. Above line would read like- #Listen 0.0.0.0:80 / 12.34.56.78:80
    5. Change the IP address and replace it with the static IP
    6. Save the httpd.conf file ensuring that the server is pointed to #Listen 192.168.1.193:80
    7. In the application root config.php (db connection) replace localhost with IP address of the server

    Note: If firewall is installed, ensure that you add the http port 80 and 8080 to exceptions and allow to listen. Go to Control Panel>Windows Firewall>Allow a program to communicate through windows firewall>Add another program Name: http Port: 80 Add one more as http - 8080

    If IIS (Microsoft .Net Application Internet Information Server) is installed with any Microsoft .Net application already on server, then it would have already occupied 80 port. In that case change the #Listen 192.168.1.193:80 to #Listen 192.168.1.193:8080

    If devices are in different network: you can use following external services to access your computer in n easy way