New in Symfony 3.3: WebServerBundle
PHP 5.4 version introduced a built-in web server that can be used to run your PHP applications locally during development without the need to configure a full-featured web server such as Apache or Nginx.
Symfony adopted this technique a while ago by providing some console commands to control that web server. In Symfony 3.3 we decided to move those commands to a new bundle called WebServerBundle.
The main reason is that moving the commands make them more easily discoverable
and more decoupled. Discoverability is specially important when not using the
symfony/symfony dependency. In that case, the commands are not available
unless you have the
symfony/process component installed. With a dedicated
bundle, installing the bundle also installs the dependency, making the whole
In any case, this new bundle won't change the way you work with the local web server:
1 2 3 4 5 6 7
# start a web server in the foreground and see the logs $ bin/console server:run # start, stop and manage a web server in the background $ bin/console server:start $ bin/console server:stop $ bin/console server:status
Creating a new bundle was also a great opportunity to introduce some DX
(developer experience) improvements in those commands and make you more
productive. First, you no longer need to pass the full address and port to
1 2 3 4 5 6 7 8
$ bin/console server:start 127.0.0.1:8888 ... # no need to pass the address again $ bin/console server:status # no need to pass the address again $ bin/console server:stop
That's possible because the web server now stores its address in a PID file
stored in the current directory. In addition, the
server:start command now
looks for a free port available automatically:
Before Symfony 3.3:
1 2 3 4 5 6 7 8 9 10
$ bin/console server:start [ERROR] A process is already listening on http://127.0.0.1:8000. $ bin/console server:start 127.0.0.1:8001 [ERROR] A process is already listening on http://127.0.0.1:8001. # ... 24 attempts later ... $ bin/console server:start 127.0.0.1:8024 [OK] Web server listening on http://127.0.0.1:8024
In Symfony 3.3:
$ bin/console server:start [OK] Web server listening on http://127.0.0.1:8024
Unless you pass the port as argument, the
server:start command now uses the
first free port available starting from
8000 and up to
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.