How to start Symfony web server from PhpStorm

Is it possible to run a Symfony web server from PhpStorm? I know I can run it from the command line:

php app/console server:run --env=dev

      

I'm just wondering if there is a way to configure PhpStorm to do this.

+3


source to share


1 answer


  • Click Run -> Edit Configurations

  • In the dialog box Click +

    (add)
  • Select PHP

    from the dropdown list
  • In the field name field Symfony Web-Server

  • In the Script field, enter the path to bin/console

    for example:/path/to/symfony/bin/console

  • Optionally uncheck the box Activate Tool Window

    to prevent it from appearing on startup
  • In the arguments box, enter server:run

  • Click "OK" to save and close the dialog

Symfony Script Web Server

This will give you the option to choose Run Symfony Web-Server

and Debug Symfony Web-Server

. To debug a running server, you must tell PHPStorm to listen for debug connections before starting the server script. To set up debugging in Settings -> Languages & Frameworks -> PHP -> Servers

, make sure you build 127.0.0.1:8000

, disable Path Mapping

, and you install Xdebug as the debugger. Optionally disable the stop in the first line in the settings Debug -> XDebug

.

PHP server settings

You can now start the server by selecting it from the Run drop-down list and clicking the Play button. Make sure to tell PHPStorm to listen for debug connections first.

Debug line



or by clicking Run -> Symfony Web-Server

.

Add breakpoints, then launch your browser on the Route affected by the breakpoints, and PHPStorm should hijack the debug session and break as desired.

debug output

If debugging fails at first, close all running PHPStorm services and try starting Debug Symfony Web-Server

(make sure PHPStorm is listening for debug connections), then restart your browser. For some reason, Xdebug may not initialize otherwise, but this behavior is sporadic and difficult to reproduce consistently. Once initialized, you can start a non-debuggable web server when listening is enabled and it seems to work fine.

Note that Debug Symfony Web-Server

only the bin / console script will control the launch . This is because the symfony server php process is forked and the debug session will be left keeping track of the parent process. So you have to say that PHPStorm is listening for debug connections when debugging the web server.

+8


source







All Articles