Prathyash Prasanthan
Prathyash Prasanthan

Reputation: 173

How can I access my localhost server from other computers?

I'm new to PHP, so I don't know how to explain it. I'm running WAMP on my computer and I would like to be able to access my localhost from another computer.

Is it possible? How can I do this?

Upvotes: 16

Views: 88122

Answers (8)

Sandy Vujaković
Sandy Vujaković

Reputation: 3

You could just tinker around the firewall. I found that the inbound and outbound rules were blocking all public network traffic (that is, all traffic to my router which is seen as public, even though it has a password) and proceeded to check the box to allow traffic on a public network (both inbound and outbound) for all the rules bearing the Apache name. Also, I did turn on the mySQL server, but that shouldn't do anything at all in this matter (though life has surprised me like this before where something insignificant turned out to be quite significant in the end, so I would do this as a last resort, but unlikely). Also, I think this should work at least over the same WiFi network (and I know that's a part of LAN, but just to clear up any ambiguity) since I only tested with my Android phone (oh how I wish I had a Windows Phone). Hope this of any use to anyone!

Upvotes: 0

tommyvn
tommyvn

Reputation: 733

If it's for testing you could use a service like http://localhost.run/ or https://ngrok.com/ to temporarily put localhost on the internet.

Upvotes: 1

kandie
kandie

Reputation: 51

This problem can be fixed as follows.This is for one using a wamp server or a similar local server. first ensure that you have modified the httpd.conf.scroll until you find this line:

#  onlineoffline tag - don't remove
Order Allow,Deny
Allow from all

If you have a smartphone turn on your wifi hotspot to connect with your pc and the one you want to connect with. Open the command prompt in your pc and type ipconfig. Note down the ip4 address of your pc (eg. 192.168.43.47) under wireless LAN adapter Wireless Network Connection.

In the pc you want to connect to set "Obtain IP address automatically". Before you connect ensure your wamp server is online. Open the browser of the client pc and type the IP address noted down earlier.This should work just fine. In some cases you may be required to switch off your antivirus.

Upvotes: 5

Lix
Lix

Reputation: 48006

This is provided that all machines are on the same network and that you have administrative privileges on the machines (you'll have to edit some system files).

You can easily do this but it would have to be a manual process.

You have to create an entry in the hosts file -

  • On Windows machines is is located in %SystemRoot%\system32\drivers\etc\hosts
  • On UNIX like systems it is located in /etc/hosts

http://en.wikipedia.org/wiki/Hosts_(file)#Location_in_the_file_system.
See the link for details on where your hosts file is located. It depends on the operating system.


The following will have to be done on every machine that you would like
to have access to your localhost machine.

Add a line at the very end of your hosts file similar to this :

10.0.0.42       prathyash-localhost.com

The IP address (in the example above it is 10.0.0.42) is the address of your localhost; Your computers IP address. The domain name (prathyash-localhost.com) is what is mapped to the IP address.

After you save that file, whenever that computer points to prathyash-localhost.com, it will be directed to your IP address. Firewalls are still a barrier - however the other answers covered that so I will not repeat their contribution.


Depending on your situation, manually editing tens maybe hundreds of files might not be feasible. In this case, you might want to consult the networks administrator (he probably hangs around on Server Fault), and he may have a better solution for you.

Upvotes: 12

Shubham
Shubham

Reputation: 22349

Post forward port 80 on your router configuration. Start wamp. Now when your IP address is accessed from any external machine it will jump to the "www" folder and show the index file. If you are not able to do so, it means your firewall is blocking the request: Disable it and try again.

Upvotes: 0

Jovan Perovic
Jovan Perovic

Reputation: 20201

@Shaun Hare explained it pretty good, however, if those computers are not in the same network (my case, when remote presentation is needed) you would also need to set port forwarding on your router and remote side would need router's public IP address.

Basically, remote side would enter http://123.123.123.123/index.php in their browser and router would point that request (via port forwarding) to WAMP server installed at 192.168.10.10 (for instance).

Upvotes: 2

Shaun Hare
Shaun Hare

Reputation: 3871

Yes if they are on the same network, simply target the computer's IP address and ensure anything on either computer that would block access to port 80 (firewalls) is off

Upvotes: 3

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799580

You can't. Bind the appropriate daemon to 0.0.0.0/:: or an external interface and use the machine's IP address.

Upvotes: 1

Related Questions