Warning: You are browsing the documentation for Symfony 4.1, which is no longer maintained.

Read the updated version of this page for Symfony 5.3 (the current stable version).

How to Use PHP’s built-in Web Server

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.

Symfony provides a web server built on top of this PHP server to simplify your local setup. This server is distributed as a bundle, so you must first install and enable the server bundle.

Installing the Web Server Bundle

Move into your project directory and run this command:

$ cd your-project/
$ composer require symfony/web-server-bundle --dev

Starting the Web Server

To run a Symfony application using PHP’s built-in web server, execute the server:start command:

$ php bin/console server:start

This starts the web server at localhost:8000 in the background that serves your Symfony application.

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:

# passing a specific IP and port
$ php bin/console server:start

# passing '*' as the IP means to use (i.e. any local IP address)
$ php bin/console server:start *:8080


You can use the server:status command to check if a web server is listening:

$ php bin/console server:status


Some systems do not support the server:start command, in these cases you can execute the server:run command. This command behaves slightly different. Instead of starting the server in the background, it will block the current terminal until you terminate it (this is usually done by pressing Ctrl and C).

Command Options

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

$ php bin/console server:start --router=config/my_router.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 bin/console server:start --docroot=public_html

Stopping the Server

When you are finished, you can stop the web server using the server:stop command:

$ php bin/console server:stop

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