使用当前稳定版本 (5.4)
如果你刚开始学习PHP,请使用最新稳定版本 PHP 5.4. PHP近年来有了巨大的改进,增加了许多强大的 新特性。不要让低版本的PHP如5.2的缺陷误导你,这些新特性是对旧版本的重要改进。如果 你想查找一个函数及其用法,可以去官方PHP手册php.net查找:
Built-in 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.
This web server was designed to aid application development. It may
also be useful for testing purposes or for application demonstrations
that are run in controlled environments. It is not intended to be a
full-featured web server. It should not be used on a public network.
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 and .zip.
MIME type support for .htm and .svg extensions was added in PHP
5.4.4. The .ogg, .ogv, and .webm extensions were added in PHP
5.4.11. The .pdf extension is recognized from PHP 5.5.5. The
.3gp, .apk, .avi, .bmp, .csv, .doc, .docx, .flac, .gz, .gzip,
.ics, .kml, .kmz, .m4a, .mp3, .mp4, .mpg, .mpeg, .mov, .odp, .ods,
.odt, .oga, .pdf, .pptx, .pps, .qt, .swf, .tar, .text, .tif, .wav,
.wmv, .xls, .xlsx and .zip extensions were added in PHP 5.5.7.
Example #1 Starting the web server
$ cd ~/public_html
$ php -S localhost:8000
The terminal will show:
PHP 5.4.0 Development Server started at Thu Jul 21 10:43:28 2011
Listening on localhost:8000
Document root is /home/me/public_html
Press Ctrl-C to quit