php 如何从其他计算机访问本地主机(xampp)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10828343/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 23:08:11  来源:igfitidea点击:

how to access localhost(xampp) from other computer

phpapachexampplocalhost

提问by Alfred

I have installed XAMPP on my computer.I want to access my localhost when typing my ip address in another computer.But when i type my ip address it takes me to my modem settings page.Please help me.(I am using the ip address from whatismyip.com)

我已经在我的电脑上安装了 XAMPP。我想在另一台电脑上输入我的 ip 地址时访问我的本地主机。但是当我输入我的 ip 地址时,它会将我带到我的调制解调器设置页面。请帮助我。(我正在使用 ip 地址来自 whatismyip.com)

回答by ltiong_sh

If you're trying to access your local XAMPP from another computer on your local network, you'll need to use a local ip address. Likely something like 192.168.x.x. (on a Windows box, you can type 'ipconfig' into a command prompt to get this IP)

如果您尝试从本地网络上的另一台计算机访问本地 XAMPP,则需要使用本地 IP 地址。可能类似于 192.168.xx(在 Windows 机器上,您可以在命令提示符中键入“ipconfig”以获取此 IP)

If you're trying to access from outside your local network, you'll need to port-forward port 80 through your router to the computer that is running your XAMPP.

如果您尝试从本地网络外部访问,则需要通过路由器将端口 80 端口转发到运行 XAMPP 的计算机。

回答by Nick Caballero

You need to open port 80 (Or whatever port you are using for Apache) on your firewall. This is pretty well documented here http://portforward.com/for most routers.

您需要在防火墙上打开端口 80(或您用于 Apache 的任何端口)。对于大多数路由器,这在http://portforward.com/ 中得到了很好的记录。

I would also recommend you get something like DynDNS, makes dynamic IPs less of a hassle.

我还建议您使用DynDNS 之类的东西,使动态 IP 不那么麻烦。

回答by Shiven

First, you need to configure your computer to get a static IP from your router. Instructions for how to do this can be found: here

首先,您需要配置计算机以从路由器获取静态 IP。可以找到有关如何执行此操作的说明:此处

For example, let's say you picked the IPaddress . After the above step is completed, you should be able to get to the website on your local machine by going to both "http://localhost" and "http://theipaddress", since your computer will now always have that IP address on your network.

例如,假设您选择了 IPaddress 。完成上述步骤后,您应该可以通过同时访问“http://localhost”和“http://theipaddress”来访问本地计算机上的网站,因为您的计算机现在将始终拥有该 IP 地址在您的网络上。

If you look up your IP address (such as "http://www.ip-adress.com/"), the IP you see is actually the IP of your router. When your friend accesses your website, you'll give him this IP. However, you need to tell your router that when it gets a request for a webpage, forward that request to your server. This is done through port forwarding.

如果你查一下你的IP地址(比如“http://www.ip-adress.com/”),你看到的IP其实就是你路由器的IP。当你的朋友访问你的网站时,你会给他这个IP。但是,您需要告诉您的路由器,当它收到网页请求时,将该请求转发到您的服务器。这是通过端口转发完成的。

Two examples of how to do this can be found here and here, although the exact screens you see will vary depending on the manufacturer of your router (Google for exact instructions, if needed).

可以在此处和此处找到有关如何执行此操作的两个示例,尽管您看到的确切屏幕会因路由器制造商而异(如果需要,请谷歌获取确切说明)。

For the Linksys router I have, I enter "http://192.168.1.1/", enter my username/password, Applications & Gaming tab > Port Range Forward. Enter the application name (whatever you want to call it), start port (80), end port (80), protocol (TCP), ip address (using the above example, you would enter 192.168.1.102, which is the static IP you assigned your server), and be sure to check to enable the forwarding. Restart your router and the changes should take effect.

对于我拥有的 Linksys 路由器,我输入“http://192.168.1.1/”,输入我的用户名/密码,应用程序和游戏选项卡 > 端口范围转发。输入应用程序名称(随便你怎么称呼它)、起始端口(80)、结束端口(80)、协议(TCP)、IP地址(使用上面的例子,你会输入192.168.1.102,这是静态IP您分配了服务器),并确保检查以启用转发。重新启动路由器,更改应该会生效。

Having done all that, your should now be able to access your webpage by going to to web browser on his machine and entering "http://IP.address.of.your.computer" (the same one you see when you go here ).

完成所有这些后,您现在应该可以访问您的网页,方法是转到他机器上的网络浏览器并输入“http://IP.address.of.your.computer”(与您在此处看到的相同) )。

As mentioned earlier, the IP address assigned to you by your ISP will eventually change whether you sign offline or not.

如前所述,无论您是否离线签名,您的 ISP 分配给您的 IP 地址最终都会改变。

I hope this helps.

我希望这有帮助。