Cover of the book Symfony 5: The Fast Track

Symfony 5: The Fast Track is the best book to learn modern Symfony development, from zero to production. +300 pages in full color showing how to combine Symfony with Docker, APIs, queues & async tasks, Webpack, Single-Page Applications, etc.

Buy printed version
WARNING: You are browsing the documentation for Symfony 2.3 which is not maintained anymore. Consider upgrading your projects to Symfony 5.1.

How to Use PHP’s built-in Web Server

2.3 version

How to Use PHP’s built-in Web Server

Since PHP 5.4 the CLI SAPI comes with a built-in web server. It can be used to run your PHP applications locally during development, for testing or for application demonstrations. This way, you don’t have to bother configuring a full-featured web server such as Apache or Nginx.


The built-in web server is meant to be run in a controlled environment. It is not designed to be used on public networks.

Starting the Web Server

Running a Symfony application using PHP’s built-in web server is as easy as executing the server:run command:

$ php app/console server:run

This starts a server at localhost:8000 that executes your Symfony application. The command will wait and will respond to incoming HTTP requests until you terminate it (this is usually done by pressing Ctrl and C).

By default, the web server listens on port 8000 on the loopback device. You can change the socket passing an IP address and a port as a command-line argument:

$ php app/console server:run

Command Options

The built-in web server expects a “router” script (read about the “router” script on as an argument. Symfony already passes such a router script when the command is executed in the prod or in the dev environment. Use the --router option in any other environment or to use another router script:

$ php app/console server:run --env=test --router=app/config/router_test.php

If your application’s document root differs from the standard directory layout, you have to pass the correct location using the --docroot option:

$ php app/console server:run --docroot=public_html

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.