Skip to content

Commit 142c826

Browse files
committed
feature symfony#4005 [Cookbook][Web server] description for running PHP's built-in web server in the background (xabbuh)
This PR was merged into the master branch. Discussion ---------- [Cookbook][Web server] description for running PHP's built-in web server in the background | Q | A | ------------- | --- | Doc fix? | no | New docs? | yes (symfony/symfony#11311) | Applies to | 2.6+ | Fixed tickets | Commits ------- 3caec21 description for running PHP's built-in web server in the background
2 parents 1afb389 + 3caec21 commit 142c826

File tree

3 files changed

+74
-11
lines changed

3 files changed

+74
-11
lines changed

book/installation.rst

+15-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,21 @@ If there are any issues, correct them now before moving on.
280280
Note that using the ACL is recommended when you have access to them
281281
on your server because changing the umask is not thread-safe.
282282

283-
**4. Use the same user for the CLI and the web server**
283+
**4. Use the built-in web server in development environments**
284+
285+
The built-in PHP web server - which can be used during development - allows
286+
your web server user and CLI user to be the same. This removes any permissions
287+
issues:
288+
289+
.. code-block:: bash
290+
291+
$ php app/console server:start
292+
293+
.. seealso::
294+
295+
Read more about the internal server :doc:`in the cookbook </cookbook/web_server/built_in>`.
296+
297+
**5. Use the same user for the CLI and the web server**
284298

285299
In development environments, it is a common practice to use the same unix
286300
user for the CLI and the web server because it avoids any of these permissions

cookbook/web_server/built_in.rst

+52-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
How 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+
711
Since PHP 5.4 the CLI SAPI comes with a `built-in web server`_. It can be used
812
to run your PHP applications locally during development, for testing or for
913
application demonstrations. This way, you don't have to bother configuring
@@ -19,25 +23,46 @@ Starting the Web Server
1923
-----------------------
2024

2125
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:
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 serves
33+
your Symfony application.
3134

3235
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:
3437

3538
.. code-block:: bash
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+
3964
Command Options
40-
---------------
65+
~~~~~~~~~~~~~~~
4166

4267
The built-in web server expects a "router" script (read about the "router"
4368
script 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,
5378
you 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

quick_tour/the_big_picture.rst

+7-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@ to run Symfony:
7676

7777
.. code-block:: bash
7878
79-
$ php app/console server:run
79+
$ php app/console server:start
80+
81+
When you are finished, you can stop it with the ``server:stop`` command:
82+
83+
.. code-block:: bash
84+
85+
$ php app/console server:stop
8086
8187
.. seealso::
8288

0 commit comments

Comments
 (0)