Wednesday, January 23, 2013

Debug PHP in Notepad++ and Windows IIS

Finally, I can debug my php code with breakpoints, watches, stepping through, etc from within Notepad++ in Windows with a website hosted in IIS on my local computer.  I have it working on Windows XP with IIS 5.1 and also on Windows 7 with IIS 7.5.

I have missed the ability to debug php for so long, having to resort to calling error_log(print_r($value, true)); all over the place when trying to locate bugs in my code er.. oops, I mean other people's code, got it?

I had to install xdebug into php, and install the DBGp plugin into Notepad++ . Just download DBGp from that link, extract and copy dbgpPlugin.dll into the plugins folder in the Notepad++ install folder (C:\Windows\Program Files\Notepad++\plugins for 32-bit systems, C:\Windows\Program Files (x86)\Notepad++\plugins for 64-bit systems).

I followed the detailed instructions here for setting it up and getting it going.

I had to change the path to the php extensions folder and the temp folder from the unix-like path to my correct Windows path. I set the xdebug output and remote log folders to the xdebug folder under the error_log folder which is defined elsewhere in the php.ini file. My php.ini on one of my PC's already had a zend section with some of the settings, so I just added the missing debug lines under that zend section.

Looks like you can use xdebug.remote_enable=On instead of xdebug.remote_enable=1. I didn't try changing the other 1's to on or 0's to off.

More details on turning debugger on and off:


Start debugging by attaching debug parameter ?XDEBUG_SESSION_START=<session name> to the test script like this:
  http://localhost/test.php?XDEBUG_SESSION_START=1

Doing so stores a cookie called XDEBUG_SESSION in the browser, which is good for one hour, and causes xdebug to try to connect to a debugger.

To stop xdebug from trying to connect to a debugger, add ?XDEBUG_SESSION_STOP parameter like this:
  http://localhost/test.php?XDEBUG_SESSION_STOP

Other Debugger Options
The xdebug website has other browser based debugger plugins, but I have not tried them yet.:

I hope this helps someone out there.

1 comment: