For the longest time I’ve been plugging away developing WordPress code and looking at the results via the web browser. If I wanted to know what value a variable has at a certain point in the code, I’d put a var_dump and see it intermingled with the web page. It’s simple and works, but I wanted to figure out how to actually run the debugger in PHPStorm and put in breakpoints.
I watched a couple of videos. The first one was what is new with PHPStorm version 9 which might be on YouTube by the time you read this and the second one was
I’m using PHPStorm 9 so I’m not sure if this will work with lower versions.
I started out by starting my local webserver which is XAMP for windows. (Later, I will try this by using a vagrant box). I made sure my PHPStorm project that I opened was the current active theme in my local XAMP webserver directory. I then clicked to the left of a php line of code to set a breakpoint which is indicated by a red circle..at least it is red in my color scheme.
I then went to the Run menu and chose Debug and clicked Edit Configurations. Clicked the plus sign to create a new configuration. Chose PHP Web Application. In the right-hand side filled in the name, ‘local’. Clicked the … button next to the server. In this new dialog, filled in a name for the server and filled out host as LocalHost. I left it at port 80 and the Debugger as Xdebug then clicked OK. Back in the Debug configuration, I made sure the server I just created was listed and left the start URL as ‘/’ and clicked apply.
Back in my project, I could now go to the Run menu and click the second option “Debug local” where ‘local’ was the name I used for the configuration.
My Chrome browser came up with my website but it didn’t stop at my breakpoint.
I went into my local php.ini file in my c:\xampp\php directory and found that the Xdebug section was commented out. I removed the semicolon on three lines and changed xdebug.remote_enable = 1 instead of 0. Here’s the end result of that section:
[XDebug] zend_extension = "C:\xampp\php\ext\php_xdebug.dll" ;xdebug.profiler_append = 0 ;xdebug.profiler_enable = 1 ;xdebug.profiler_enable_trigger = 0 ;xdebug.profiler_output_dir = "C:\xampp\tmp" ;xdebug.profiler_output_name = "cachegrind.out.%t-%s" xdebug.remote_enable = 1 ;xdebug.remote_handler = "dbgp" ;xdebug.remote_host = "127.0.0.1" xdebug.trace_output_dir = "C:\xampp\tmp"
After restarting my XAMP Apache server, I ran Debug local again and the debugger started up and I could see the code and step through it.
PHPStorm 9 also does something cool. The edit screen shows the values of all variables as you step through it. Sweet!