In order to debug symfony or php apps that uses front end controller approach, you need to have several things:
- Configure Xdebug. I prefer to use the
On-Demand mode
, but beware that it's only applicable to cli scripts / code coverage reports. Make sure that you set thexdebug.mode=debug
andxdebug.idekey=PHPSTORM
. This will be usefull in case you need to Debugging Symfony commands.
- To debug incoming http request, you need to have a webserver running configuration. We'll use the
PHP Built-in Web Server
as it's sufficient for our purpose. Click Run > Edit Configurations > Add New Configuration > PHP Built-in Web Server. Use port8000
and document root to be$PROjECT_DIR/public
where$PROjECT_DIR
is the path of your project. Sadly, since XdebugOn-Demand mode
is not working for this web server, you need to have separatephp.ini
config and use that for theInterpreter options
. Here I set it as-c /home/rizalp/Dropbox/appConfig/php/lib/php.xdebug.ini
. InEnvironment Variables
field, addXDEBUG_SESSION=1
to activate the debugger. ClickOk
to save the configuration. Name itSymfony PHP Server
or anything.
To start debugging
- Put breakpoint on the line that you want to debug
- Run >
Start Listening for PHP Debug Connections
- Run >
Run Symfony PHP Server
- There will be dialog window from the PHPStorm about the incoming connections from xdebug. Click
Accept
. - Send http request. The execution will break at the line where you put the breakpoint