PHP built-in server

suggest change

PHP 5.4+ comes with a built-in development server. It can be used to run applications without having to install a production HTTP server such as nginx or Apache. The built-in server is only designed to be used for development and testing purposes.

It can be started by using the -S flag:

php -S <host/ip>:<port>

Example usage

  1. Create an index.php file containing:
    <?php
    echo "Hello World from built-in PHP server";
  2. Run the command php -S localhost:8080 from the command line. Do not include http://. This will start a web server listening on port 8080 using the current directory that you are in as the document root.
  3. Open the browser and navigate to http://localhost:8080. You should see your “Hello World” page.

Configuration

To override the default document root (i.e. the current directory), use the -t flag:

php -S <host/ip>:<port> -t <directory>

E.g. if you have a public/ directory in your project you can serve your project from that directory using php -S localhost:8080 -t public/.

Logs

Every time a request is made from the development server, a log entry like the one below is written to the command line.

[Mon Aug 15 18:20:19 2016] ::1:52455 [200]: /

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Getting started:
* PHP built-in server

Table Of Contents
0 Getting started
2 Arrays
4 Types
10 Cookies
14 JSON
15 SOAP
17 cURL
19 XML
21 Traits
35 UTF-8
36 URLs
38 PHPDoc
41 Loops
44 Closur
72 YAML
77 Cache
78 Streams
81 PDO
82 SQLite3
83 Sockets
87 MongoDB
93 IMAP
94 Redis
95 Imagick
102 APCu
108 PSR