4
4
How to Use PHP's built-in Web Server
5
5
====================================
6
6
7
+ .. versionadded :: 2.6
8
+ The ability to run the server as a background process was introduced
9
+ in Symfony 2.6.
10
+
7
11
Since PHP 5.4 the CLI SAPI comes with a `built-in web server `_. It can be used
8
12
to run your PHP applications locally during development, for testing or for
9
13
application demonstrations. This way, you don't have to bother configuring
@@ -19,25 +23,46 @@ Starting the Web Server
19
23
-----------------------
20
24
21
25
Running 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:
23
27
24
28
.. code-block :: bash
25
29
26
- $ php app/console server:run
30
+ $ php app/console server:start
27
31
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 serves
33
+ your Symfony application.
31
34
32
35
By default, the web server listens on port 8000 on the loopback device. You
33
- can change the socket passing an ip address and a port as a command-line argument:
36
+ can change the socket passing an IP address and a port as a command-line argument:
34
37
35
38
.. code-block :: bash
36
39
37
40
$ php app/console server:run 192.168.0.1:8080
38
41
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
+
39
64
Command Options
40
- ---------------
65
+ ~~~~~~~~~~~~~~~
41
66
42
67
The built-in web server expects a "router" script (read about the "router"
43
68
script on `php.net `_) as an argument. Symfony already passes such a router
@@ -47,14 +72,32 @@ script:
47
72
48
73
.. code-block :: bash
49
74
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
51
76
52
77
If your application's document root differs from the standard directory layout,
53
78
you have to pass the correct location using the ``--docroot `` option:
54
79
55
80
.. code-block :: bash
56
81
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
58
101
59
102
.. _`built-in web server` : http://www.php.net/manual/en/features.commandline.webserver.php
60
103
.. _`php.net` : http://php.net/manual/en/features.commandline.webserver.php#example-401
0 commit comments