php 如何从其他计算机访问我的本地主机服务器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10064630/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I access my localhost server from other computers?
提问by Prathyash Prasanthan
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 mylocalhost from another computer.
我是 PHP 新手,所以我不知道如何解释它。我在我的计算机上运行 WAMP,我希望能够从另一台计算机访问我的本地主机。
Is it possible? How can I do this?
是否可以?我怎样才能做到这一点?
采纳答案by Lix
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
- 在 Windows 机器上位于
%SystemRoot%\system32\drivers\etc\hosts - 在类 UNIX 系统上,它位于
/etc/hosts
http://en.wikipedia.org/wiki/Hosts_(file)#Location_in_the_file_system.
See the link for details on where yourhosts file is located. It depends on the operating system.
http://en.wikipedia.org/wiki/Hosts_(file)#Location_in_the_file_system。
查看其中的链接了解详细信息您的hosts文件的位置。这取决于操作系统。
The following will have to be done on every machine that you would like
to have access to your localhostmachine.
必须在您希望
访问您的localhost机器的每台机器上执行以下操作。
Add a line at the very end of your hosts file similar to this :
在 hosts 文件的最后添加一行,类似于:
10.0.0.42 prathyash-localhost.com
The IP address (in the example above it is 10.0.0.42) is the address of yourlocalhost; Your computers IP address. The domain name (prathyash-localhost.com) is what is mappedto the IP address.
IP 地址(在上面的例子中是10.0.0.42)是你的本地主机的地址;您的计算机 IP 地址。域名 ( prathyash-localhost.com) 是映射到 IP 地址的内容。
After you save that file, whenever thatcomputer 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.
保存该文件后,只要该计算机指向prathyash-localhost.com,它就会被定向到您的 IP 地址。防火墙仍然是一个障碍——但是其他答案涵盖了这一点,所以我不会重复他们的贡献。
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.
根据您的情况,手动编辑数十个甚至数百个文件可能不可行。在这种情况下,您可能需要咨询网络管理员(他可能在Server Fault上徘徊),他可能会为您提供更好的解决方案。
回答by kandie
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:
这个问题可以解决如下。这是针对使用 wamp 服务器或类似本地服务器的人。首先确保你已经修改了 httpd.conf.scroll 直到你找到这一行:
# 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.
如果您有智能手机,请打开您的 wifi 热点以连接您的电脑和您想要连接的电脑。在您的电脑中打开命令提示符并键入 ipconfig。在无线 LAN 适配器无线网络连接下记下您电脑的 ip4 地址(例如 192.168.43.47)。
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.
在要连接的电脑上设置“自动获取IP地址”。在连接之前,请确保您的 wamp 服务器在线。打开客户端电脑的浏览器并输入之前记下的 IP 地址。这应该可以正常工作。在某些情况下,您可能需要关闭防病毒软件。
回答by Shaun Hare
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
是的,如果它们在同一网络上,只需将计算机的 IP 地址作为目标,并确保任何一台计算机上阻止访问端口 80(防火墙)的任何内容都已关闭
回答by Jovan Perovic
@Shaun Hareexplained 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 forwardingon your router and remote side would need router's public IP address.
@Shaun Hare解释得很好,但是,如果这些计算机不在同一网络中(我的情况,需要远程演示时),您还需要在路由器上设置端口转发,而远程端则需要路由器的公共 IP 地址。
Basically, remote side would enter http://123.123.123.123/index.phpin their browser and router would point that request (via port forwarding) to WAMP server installed at 192.168.10.10(for instance).
基本上,远程端会http://123.123.123.123/index.php在他们的浏览器中输入,路由器会将该请求(通过端口转发)指向安装在192.168.10.10(例如)的WAMP 服务器。
回答by Ignacio Vazquez-Abrams
You can't. Bind the appropriate daemon to 0.0.0.0/:: or an external interface and use the machine's IP address.
你不能。将适当的守护进程绑定到 0.0.0.0/:: 或外部接口并使用机器的 IP 地址。
回答by tommyvn
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.
如果是为了测试,您可以使用像http://localhost.run/或https://ngrok.com/这样的服务来临时将 localhost 放在互联网上。
回答by Sandy Vujakovi?
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!
你可以修补防火墙。我发现入站和出站规则阻止了所有公共网络流量(也就是说,所有到我路由器的流量都被视为公共流量,即使它有密码)并继续选中该框以允许公共网络上的流量(入站和出站)适用于所有带有 Apache 名称的规则。此外,我确实打开了 mySQL 服务器,但在这件事上根本不应该做任何事情(尽管生活之前让我感到惊讶,但最终发现一些无关紧要的事情变得非常重要,所以我会这样做最后的手段,但不太可能)。另外,我认为这至少应该在同一个 WiFi 网络上工作(我知道这是 LAN 的一部分,但只是为了消除任何歧义)因为我只用我的 Android 手机测试过(哦,我多么希望我有一个 Windows Phone )。
回答by Shubham
Post forward port 80on 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.
在路由器配置上发布转发端口 80。开始wamp。现在,当从任何外部机器访问您的 IP 地址时,它将跳转到“www”文件夹并显示索引文件。如果您无法这样做,则意味着您的防火墙正在阻止该请求:禁用它并重试。

