Skip to content

Instantly share code, notes, and snippets.

@rizalp
Last active November 5, 2021 03:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rizalp/6a0390ec9fe494b94e0f0f83b163bd5d to your computer and use it in GitHub Desktop.
Save rizalp/6a0390ec9fe494b94e0f0f83b163bd5d to your computer and use it in GitHub Desktop.
[Debugging Symfony Controller Using PHPStorm] step by step guide on how to do debugging on PHPStorm using Xdebug #symfony #xdebug #phpstorm #php

Debugging Symfony Controller Using PHPStorm

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 the xdebug.mode=debug and xdebug.idekey=PHPSTORM. This will be usefull in case you need to Debugging Symfony commands.

debug-symfony-phpstorm-1

  • 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 port 8000 and document root to be $PROjECT_DIR/public where $PROjECT_DIR is the path of your project. Sadly, since Xdebug On-Demand mode is not working for this web server, you need to have separate php.ini config and use that for the Interpreter options. Here I set it as -c /home/rizalp/Dropbox/appConfig/php/lib/php.xdebug.ini. In Environment Variables field, add XDEBUG_SESSION=1 to activate the debugger. Click Ok to save the configuration. Name it Symfony PHP Server or anything.

debug-symfony-phpstorm-2

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

debug-symfony-phpstorm-3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment