在localhost外部运行PHP 5.4内置Web服务器 [英] Running PHP 5.4 built-in web server outside localhost

查看:100
本文介绍了在localhost外部运行PHP 5.4内置Web服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是的,即将发布的PHP 5.4中有一个内置的Web服务器,您可以在他们的候选版本中试用(我最近也发现了这一点!)

Yes, there's a built-in web server in the upcoming release of PHP 5.4 which you can try out in their release candidates (I found about this just recently too!)

http://php.net/manual/en/features.commandline.webserver.php

我需要弄清楚的是,有什么方法可以使其在除localhost之外的其他域名上运行(在localhost,端口80上运行正常)?甚至127.0.0.1也不起作用.我在主机文件中输入了虚拟主机名,使其指向127.0.0.1,但它们也无法正常工作.我知道这只是一个候选版本,但我想知道是否其他人已经针对此问题提出了解决方案,以便我可以使用在我的主机文件中指向127.0.0.1的实际域名来测试我的应用程序.操作系统是Windows 7 Professional SP1.

What I need help figuring out is, is there any way to make it run on domain names other than localhost (it's running fine on localhost, port 80)? Even 127.0.0.1 doesn't work. I've put in dummy hostnames in my hosts file to point to 127.0.0.1 and they don't work too. I understand that it's just a release candidate, but I would like to know whether anyone else has already come up with a solution for this issue so that I can test my app with the actual domain name pointing to 127.0.0.1 in my hosts file. OS is Windows 7 Professional SP1.

我已经尝试过的东西: 1.谷歌搜索(duh) 2.通过php.ini查找选项 3.试用127.0.0.1,转发了我的LAN IP,转发了端口80的WAN IP和NAT回送问题(运行DD-WRT的路由器)

Things I've already tried: 1. Googling (duh) 2. Looking through php.ini for options 3. Trying out 127.0.0.1, my LAN IP, my WAN IP with port 80 forwarded and NAT loopback issue fixed (router running DD-WRT)

推荐答案

我在Windows XP系统上进行了这些测试,但通过修改命令在Linux上也应如此.

I did these tests on a Windows XP system, but should work the same on Linux as well by modifying the commands.

像这样运行您的PHP测试服务器:

Run your PHP test server like this:

C:/php/php.exe -S 0.0.0.0:80
or
/usr/bin/php -S 0.0.0.0:80

0.0.0.0将绑定到系统上所有可用的IP地址.

0.0.0.0 will bind to all available IP addresses on the system.

在网络上的另一台计算机上,我将hosts文件配置为使用自定义域指向运行PHP的系统的内部IP.这不是127.0.0.1,因为它是指本地主机,在我的情况下,我将主PC指向192.168.88.247,这是运行PHP的XP机器.请注意,应禁用防火墙或将防火墙设置为允许运行php的计算机上端口80上的流量.

On another machine on the network, I configured the hosts file to point to the internal IP of the system running PHP using a custom domain. This is not 127.0.0.1 as that refers to the local host, in my case I pointed my main PC to 192.168.88.247 which was the XP machine running PHP. Note the firewall should be disabled or set to allow traffic on port 80 on the machine running php.

我将路由器配置为将转发流量从外部端口80转发到192.168.88.247:80.然后,使用来自外部网络的PC上的主机文件,我将伪造域配置为指向我的WAN IP.我可以从外部访问PHP Web服务器.

I configured my router to port forward traffic from external port 80 to 192.168.88.247:80. Then using a hosts file on a PC from an external network, I configured the fake domain to point to my WAN IP. I was able to access the PHP web server externally.

也就是说,它只是一个用于测试的服务器,因此可能存在未知的安全风险,将其向外界开放.

That said, it is just a server for testing, so there may be unknown security risks opening it up to the outside world.

希望对您有帮助.

这篇关于在localhost外部运行PHP 5.4内置Web服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆