|
| 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 |
0 commit comments