Skip to content

Commit 57f467a

Browse files
committed
add cookbook article for the server:run command
1 parent 4b93ef0 commit 57f467a

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed

cookbook/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ The Cookbook
2828
templating/index
2929
testing/index
3030
validation/index
31+
web_server/index
3132
web_services/index
3233
workflow/index
3334

cookbook/map.rst.inc

+5
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@
191191

192192
* :doc:`/cookbook/validation/custom_constraint`
193193

194+
* :doc:`/cookbook/web_server/index`
195+
196+
* :doc:`/cookbook/web_server/built_in`
197+
* (configuration) :doc:`/cookbook/configuration/web_server_configuration`
198+
194199
* :doc:`/cookbook/web_services/index`
195200

196201
* :doc:`/cookbook/web_services/php_soap_extension`

cookbook/web_server/built_in.rst

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
.. index::
2+
single: Web Server; Built-in Web Server
3+
4+
How to Use PHP's built-in Web Server
5+
====================================
6+
7+
Since PHP 5.4 the CLI SAPI comes with a `built-in web server`_. It can be used
8+
to run your PHP applications locally during development, for testing or for
9+
application demonstrations. This way, you don't have to bother configuring
10+
a full-featured web server such as
11+
:doc:`Apache or Nginx </cookbook/configuration/web_server_configuration>`.
12+
13+
.. caution::
14+
15+
The built-in web server is meant to be run in a controlled environment.
16+
It is not designed to be used on public networks.
17+
18+
Starting the Web Server
19+
-----------------------
20+
21+
Running a Symfony application using PHP's built-in web server is as easy as
22+
executing the ``server:run`` command:
23+
24+
.. code-block:: bash
25+
26+
$ php app/console server:run
27+
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).
31+
32+
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:
34+
35+
.. code-block:: bash
36+
37+
$ php app/console server:run 192.168.0.1:8080
38+
39+
Command Options
40+
---------------
41+
42+
The built-in web server expects a "router" script (read about the "router"
43+
script on `php.net`_) as an argument. Symfony already passes such a router
44+
script when the command is executed in the ``prod`` or in the ``dev`` environment.
45+
Use the ``--router`` option in any other environment or to use another router
46+
script:
47+
48+
.. code-block:: bash
49+
50+
$ php app/console server:run --env=test --router=app/config/router_test.php
51+
52+
If your application's document root differs from the standard directory layout,
53+
you have to pass the correct location using the ``--docroot`` option:
54+
55+
.. code-block:: bash
56+
57+
$ php app/console server:run --docroot=public_html
58+
59+
.. _`built-in web server`: http://www.php.net/manual/en/features.commandline.webserver.php
60+
.. _`php.net`: http://php.net/manual/en/features.commandline.webserver.php#example-401

cookbook/web_server/index.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Web Server
2+
==========
3+
4+
.. toctree::
5+
:maxdepth: 2
6+
7+
built_in

quick_tour/the_big_picture.rst

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ to run Symfony:
5757
5858
$ php app/console server:run
5959
60+
.. seealso::
61+
62+
Read more about the internal server :doc:`in the cookbook </cookbook/web_server/built_in>`.
63+
6064
If you get the error `There are no commands defined in the "server" namespace.`,
6165
then you are probably using PHP 5.3. That's ok! But the built-in web server is
6266
only available for PHP 5.4.0 or higher. If you have an older version of PHP or

0 commit comments

Comments
 (0)