Skip to content
  • About
    • What is Symfony?
    • Community
    • News
    • Contributing
    • Support
  • Documentation
    • Symfony Docs
    • Symfony Book
    • Screencasts
    • Symfony Bundles
    • Symfony Cloud
    • Training
  • Services
    • Platform.sh for Symfony Best platform to deploy Symfony apps
    • SymfonyInsight Automatic quality checks for your apps
    • Symfony Certification Prove your knowledge and boost your career
    • SensioLabs Professional services to help you with Symfony
    • Blackfire Profile and monitor performance of your apps
  • Other
  • Blog
  • Download
sponsored by SensioLabs
  1. Home
  2. Documentation
  3. Setup
  4. How to Use PHP's built-in Web Server
  • Documentation
  • Book
  • Reference
  • Bundles
  • Cloud

Table of Contents

  • Starting the Web Server
    • Command Options
  • Stopping the Server

How to Use PHP's built-in Web Server

Edit this page

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

Read the updated version of this page for Symfony 6.3 (the current stable 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.

Caution

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:start command:

1
$ 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:

1
$ php bin/console server:start 192.168.0.1:8080

Note

You can use the --force option to force the web server start if the process wasn't correctly stopped (without using the server:stop command).

1
$ php bin/console server:start --force

Note

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

1
2
3
$ php bin/console server:status

$ php bin/console server:status 192.168.0.1:8080

The first command shows if your Symfony application will be server through localhost:8000, the second one does the same for 192.168.0.1:8080.

Tip

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).

Using the built-in Web Server from inside a Virtual Machine

If you want to use the built-in web server from inside a virtual machine and then load the site from a browser on your host machine, you'll need to listen on the 0.0.0.0:8000 address (i.e. on all IP addresses that are assigned to the virtual machine):

1
$ php bin/console server:start 0.0.0.0:8000

Caution

You should NEVER listen to all interfaces on a computer that is directly accessible from the Internet. The built-in web server is not designed to be used on public networks.

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 in the dev environment. Use the --router option in any other environment or to use another router script:

1
$ php bin/console server:start --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:

1
$ php bin/console server:start --docroot=public_html

Stopping the Server

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

1
$ php bin/console server:stop

Like with the start command, if you omit the socket information, Symfony will stop the web server bound to localhost:8000. Just pass the socket information when the web server listens to another IP address or to another port:

1
$ php bin/console server:stop 192.168.0.1:8080
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
TOC
    Version
    We stand with Ukraine.
    Version:
    Measure & Improve Symfony Code Performance

    Measure & Improve Symfony Code Performance

    Be trained by SensioLabs experts (2 to 6 day sessions -- French or English).

    Be trained by SensioLabs experts (2 to 6 day sessions -- French or English).

    Symfony footer

    ↓ Our footer now uses the colors of the Ukrainian flag because Symfony stands with the people of Ukraine.

    Avatar of Lars Moelleken, a Symfony contributor

    Thanks Lars Moelleken for being a Symfony contributor

    1 commit • 3 lines changed

    View all contributors that help us make Symfony

    Become a Symfony contributor

    Be an active part of the community and contribute ideas, code and bug fixes. Both experts and newcomers are welcome.

    Learn how to contribute

    Symfony™ is a trademark of Symfony SAS. All rights reserved.

    • What is Symfony?

      • Symfony at a Glance
      • Symfony Components
      • Case Studies
      • Symfony Releases
      • Security Policy
      • Logo & Screenshots
      • Trademark & Licenses
      • symfony1 Legacy
    • Learn Symfony

      • Symfony Docs
      • Symfony Book
      • Reference
      • Bundles
      • Best Practices
      • Training
      • eLearning Platform
      • Certification
    • Screencasts

      • Learn Symfony
      • Learn PHP
      • Learn JavaScript
      • Learn Drupal
      • Learn RESTful APIs
    • Community

      • SymfonyConnect
      • Support
      • How to be Involved
      • Code of Conduct
      • Events & Meetups
      • Projects using Symfony
      • Downloads Stats
      • Contributors
      • Backers
    • Blog

      • Events & Meetups
      • A week of symfony
      • Case studies
      • Cloud
      • Community
      • Conferences
      • Diversity
      • Documentation
      • Living on the edge
      • Releases
      • Security Advisories
      • SymfonyInsight
      • Twig
      • SensioLabs
    • Services

      • SensioLabs services
      • Train developers
      • Manage your project quality
      • Improve your project performance
      • Host Symfony projects

      Deployed on

    Follow Symfony

    Search by Meilisearch