As of PHP 5.4.0, the CLI SAPI provides a built-in web server was designed to aid application development (It is not intended to be a full-featured web server).
As of PHP 5.4.0, the CLI SAPI provides a built-in web server.
PHP applications will stall if a request is blocked.
URI requests are served from the current working directory where PHP was started, unless the -t
option is used to specify an explicit document root. If a URI request does not specify a file, then either index.php
or index.html
in the given directory are returned. If neither file exists, then a 404 response
code is returned.
If a PHP file is given on the command line when the web server is started it is treated as a "router" script. The script is run at the start of each HTTP request. If this script returns FALSE
, then the requested resource is returned as-is. Otherwise the script's output is returned to the browser.
Standard MIME types are returned for files with extensions: .3gp, .apk, .avi, .bmp, .css, .csv, .doc, .docx, .flac, .gif, .gz, .gzip, .htm, .html, .ics, .jpe, .jpeg, .jpg, .js, .kml, .kmz, .m4a, .mov, .mp3, .mp4, .mpeg, .mpg, .odp, .ods, .odt, .oga, .ogg, .ogv, .pdf, .pdf, .png, .pps, .pptx, .qt, .svg, .swf, .tar, .text, .tif, .txt, .wav, .webm, .wmv, .xls, .xlsx, .xml, .xsl, .xsd, and .zip.
Example:
php -S localhost:8000 -t /home/user/foo/
Source: Built-in web server