How to run Symfony web server from PhpStorm How to run Symfony web server from PhpStorm symfony symfony

How to run Symfony web server from PhpStorm


Symfony WebServer Bundle Setup

  • Click Run -> Edit Configurations
  • In the dialog box Click + (add)
  • Select PHP Script from the drop down list
  • In the name field type Symfony Web-Server
  • In the Script field put the path to your bin/consoleeg: /path/to/symfony/bin/console
  • Optionally uncheck Activate Tool Window to prevent it from popping up when started
  • In the arguments field type server:run
  • Click Ok to save and close the dialog box

Symfony Web-Server Script

This will provide you with a Run Symfony Web-Server and Debug Symfony Web-Server option to select. To debug the running server, you must tell PHPStorm to listen for debug connections prior to running the server script. To configure debugging in your Settings -> Languages & Frameworks -> PHP -> Servers ensure you have 127.0.0.1:8000 created, disable Path Mapping and you have Xdebug set as the debugger. Optionally disable stop at first line in the Debug -> XDebug settings.

PHP Server Settings

Now you can start the server by selecting it in your Run configuration drop down, and clicking the Play button, or by clicking Run -> Symfony Web-Server.

Be sure to tell PHPStorm to Listen for Debug connections first.

Debug bar

Add breakpoints, then launch your browser to a Route affected by the breakpoint(s) and PHPStorm should capture the debug session and break as desired.

debug output

If debugging fails at first, close all of the running PHPStorm services, and try running the Debug Symfony Web-Server (ensuring that PHPStorm is listening for Debug Connections) and then re-launch your browser.For some reason Xdebug may not initialize otherwise, but this behavior is sporadic and hard to reproduce consistently. After it initializes you can run the non-debug web-server while listening is enabled, and it seems to work fine.

Special note, running the Debug Symfony Web-Server will only monitorthe bin/console script. This is because the Symfony server php processis forked and the debug session will be left monitoring the parentprocess. So you must tell PHPStorm to listen for debug connectionswhen debugging the web server.


Symfony CLI setup

The Symfony Web-Server was added to the new Symfony CLI binary. To continue using the Symfony web server as a PHP Script, described above, you must install the symfony/web-server-bundle compatible with your version of Symfony.

The symfony/web-server-bundle is depreciated as of Symfony 4.4 and will be removed in Syfmony 5.0

To set up the Symfony CLI web-server in PHPStorm, you can create an External Tool.

Program: symfony Arguments: server:start --no-tlsWorking Directory: $ProjectFileDir$

PHPStorm External Tools

You can then run the command from your Tools menu.

PHPStorm symfony server:start

Or you can execute it from a Run/Debug configuration, similarly to the Symfony WebServer Bundle configuration above, that instead executes the External Tool you created.

PHPStorm symfony server:start configuration

When running either of the above, you should get a new Run dialog CLI inside PHPStorm.

PHPStorm Run symfony server:start

As the Symfony CLI web-server runs outside of the PHP script configuration, it does not suffer the random issues with X-Debug and PHPStorm not listening. I was unable to reproduce the issues in my testing.

However, PHPStorm requires that your server host be changed from http://localhost to http://localhost:8000 for the X-Debug path mapping in PHPStorm to work.

If you do not update the host, PHPStorm will prompt you for the configuration when it encounters a break-point, just click Accept for a new server to be automatically added.

PHPStorm Incoming COnnection from X-Debug

Result

Syfmony 5 server X-Debug


To setup Symfony CLI on Windows you can use Bash template:

  1. Click Run -> Edit Configurations
  2. In the dialog box Click + (add)
  3. Select Bash from the drop down list
  4. In the name field type Symfony server
  5. In the Script field type serve
  6. In the Interpreter path field put the path to your command console eg: C:\Windows\System32\cmd.exe
  7. In the Interpreter options field type /k "symfony"
  8. In the Program arguments field type --no-tls

Click Ok to save and close the dialog box

Edit Configurations dialog box

Now you can start and stop Symfony server from the top panel:

Run Server