Using the built-in php web server

As you may know or not, as of PHP version 5.4.0 the CLI SAPI has built-in web server, which of course has been added for development purposes only (so don’t use it in production!). Starting the web server is quite simple – go into the folder containing your php scripts and execute php with the -S option, e.g.:

php -S localhost:8080

or if you want to provide the folder path instead of going into it, can use the -t option (using /home/wwwdata/ in the example bellow):

php -S localhost:8080 -t /home/wwwdata/

Then just go to your browser, open localhost:8080 and that’s it! As proof of concept you could create in that folder sample hello.php containing the so-boring <?php echo “Hello World!” ?> and then check the result in your browser using http://localhost:8080/hello.php

When specific php file isn’t provided in the URL, then the built-in web server tries to serve either of index.php or index.html (whichever exists). Also keep in mind that when using localhost (binding it to 127.0.0.1) you’ll be able to open it only on your PC, so if you need accessible from “outside” your PC or just listening on another interface, either use that interface IP or 0.0.0.0 for all interfaces instead of localhost:

php -S 0.0.0.0:8080

Then, if (for example) you have interface eth0 with IP 10.0.0.10, you’ll be able to access the web server via http://10.0.0.10:8080/