Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running PHP 5.4 built-in web server outside localhost

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

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.

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)

like image 760
Shanshui Avatar asked Dec 04 '11 17:12

Shanshui


People also ask

Does PHP have a Web server?

The built-in PHP web server can be run on any computer that has PHP installed. (Apple computers already have PHP installed, but if you're on Windows or Linux you may need to run a PHP installer.) The PHP built-in server is used to aid in writing PHP scripts without having to run a full stack web server.

What is a PHP web server?

PHP server is a collection of tools that make hosting at local servers possible so you can build or develop Web Apps at your computer. If you are going to develop a web application, having a PHP server is the best way to begin.

What server is PHP running on?

To run PHP for the web, you need to install a Web Server like Apache and you also need a database server like MySQL. There are various web servers for running PHP programs like WAMP & XAMPP. WAMP server is supported in windows and XAMP is supported in both Windows and Linux.


1 Answers

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

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 will bind to all available IP addresses on the system.

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.

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.

Hope that helps you.

like image 105
drew010 Avatar answered Oct 08 '22 14:10

drew010