44How to Use PHP's built-in Web Server
55====================================
66
7+ ..versionadded ::2.6
8+ The ability to run the server as a background process was introduced
9+ in Symfony 2.6.
10+
711Since PHP 5.4 the CLI SAPI comes with a `built-in web server `_. It can be used
812to run your PHP applications locally during development, for testing or for
913application demonstrations. This way, you don't have to bother configuring
@@ -19,15 +23,14 @@ Starting the Web Server
1923-----------------------
2024
2125Running a Symfony application using PHP's built-in web server is as easy as
22- executing the ``server:run `` command:
26+ executing the ``server:start `` command:
2327
2428..code-block ::bash
2529
26- $ php app/console server:run
30+ $ php app/console server:start
2731
28- This starts a server at ``localhost:8000 `` that executes your Symfony application.
29- The command will wait and will respond to incoming HTTP requests until you
30- terminate it (this is usually done by pressing Ctrl and C).
32+ This starts the web server at ``localhost:8000 `` in the background that will
33+ serve your Symfony application.
3134
3235By default, the web server listens on port 8000 on the loopback device. You
3336can change the socket passing an ip address and a port as a command-line argument:
@@ -36,8 +39,30 @@ can change the socket passing an ip address and a port as a command-line argumen
3639
3740 $ php app/console server:run 192.168.0.1:8080
3841
42+ ..note ::
43+
44+ You can use the ``server:status `` command to check if a web server is
45+ listening on a certain socket:
46+
47+ ..code-block ::bash
48+
49+ $ php app/console server:status
50+
51+ $ php app/console server:status 192.168.0.1:8080
52+
53+ The first command shows if your Symfony application will be server through
54+ ``localhost:8000 ``, the second one does the same for ``192.168.0.1:8080 ``.
55+
56+ ..note ::
57+
58+ Before Symfony 2.6, the ``server:run `` command was used to start the built-in
59+ web server. This command is still available and behaves slightly different.
60+ Instead of starting the server in the background, it will block the current
61+ terminal until you terminate it (this is usually done by pressing Ctrl
62+ and C).
63+
3964Command Options
40- ---------------
65+ ~~~~~~~~~~~~~~~
4166
4267The built-in web server expects a "router" script (read about the "router"
4368script on `php.net `_) as an argument. Symfony already passes such a router
@@ -47,14 +72,32 @@ script:
4772
4873..code-block ::bash
4974
50- $ php app/console server:run --env=test --router=app/config/router_test.php
75+ $ php app/console server:start --env=test --router=app/config/router_test.php
5176
5277 If your application's document root differs from the standard directory layout,
5378you have to pass the correct location using the ``--docroot `` option:
5479
5580..code-block ::bash
5681
57- $ php app/console server:run --docroot=public_html
82+ $ php app/console server:start --docroot=public_html
83+
84+ Stopping the Server
85+ -------------------
86+
87+ When you are finished, you can simply stop the web server using the ``server:stop ``
88+ command:
89+
90+ ..code-block ::bash
91+
92+ $ php app/console server:stop
93+
94+ Like with the start command, if you omit the socket information, Symfony will
95+ stop the web server bound to ``localhost:8000 ``. Just pass the socket information
96+ when the web server listens to another ip address or to another port:
97+
98+ ..code-block ::bash
99+
100+ $ php app/console server:stop 192.168.0.1:8080
58101
59102 .. _`built-in web server` :http://www.php.net/manual/en/features.commandline.webserver.php
60103.. _`php.net` :http://php.net/manual/en/features.commandline.webserver.php#example-401