Since I may have to do some PHP programming in the near future, I have been looking for a nice IDE over the last week. For syntax highlighting and simple editing, Notepad++ has been doing the job so far, but I’m getting sick and tired of having to use the print() command to output variables I need to check. Thus, code debugging was one of the mandatory features I was aiming for in my conquest for an IDE. As of yet, I have been using Eclipse for my Java programming, being very satisfied with its feature list as well as its GUI and the fact that it’s supported by a huge community. Furthermore, it’s open-source (therefore freely available) and easily extensible through hundrets of plugins, available via the Eclipse-internal software update mechanism.

Fortunately, there are also two PHP plugins available: the PDT framework (f.k.a. PHP IDE), which leverages the Web Tools Platform (WPT) project, as well as the classic PHPEclipse plugin. While development for the latter is supposedly slow and there seem to be compatibility issues with the latest releases of Eclipse, PDT (introduced by Zend in 2006) allows server-side debugging only through the proprietary Zend Web Server Debugger. This is why I went with the PHPEclipse plugin.

The installation instructions I found were pretty outdated, but still did their job. If you haven’t already done so, go ahead and install XAMPP on your system. Under my Win XP SP2 system it installs to C:\\xampp. If you have installed it to any other directory (e.g. C:\\Program Files\…) you may want to change the document root as explained here.

Next, for remote debugging to work properly, you need to download and install the proper DBG modules for your apache installation. Get the appropriate (win or linux) module here and unzip the files. Rename and install the module according to these instructions. When setting up the php.ini file, pay close attention to which file you edit!!! At first I made changes to C:\\xampp\php\php.ini while I would have actually had to edit C:\\xampp\apache\bin\php.ini. To avoid glitches, I also commented out all the lines concerning the Zend debugger. After restarting your server, your phpinfo() output should now list a “dbg” section.

To setup debugging in Eclipse, follow these instructions. In addition you may want to consider this site. Be sure not to mixup CLI debugging with server-side debugging like I did at first: After setting up everything as told in the tutorial, I started a debug session with a simple php script called simple.php, which resides in my htdocs folder:

<?php
$msg = "This is a message";
$aThings = array('one', 'two', 'three', 'four', 'five');
foreach ($aThings as $value) {
print $msg . ' - ' . $value . ' ';
}
?>

I set a breakpoint on the second line, clicked the debug button and wondered, why the breakpoint wasn’t hit, when I switched to the Debug Perspective. Of course, this would have happened, if I had setup a CLI debug session as in that case Eclipse would have just debugged my local .php file. The setup mentioned above, though, proceeds on the assumption of a server-side executed php script and therefore Eclipse connects to a pre-defined port of your webserver (DBG’s default is 7869. This is configured in the php.ini) and listenes for debug messages. Therefore the breakpoint may not be hit, until someone actually calls the php script on the server. So in order to reach the breakpoint you will have to direct your external or the Eclipse-internal browser to the the php-file’s URL, extended by the debug session ID and the debug port, so in my case

http://localhost/simple.php?DBGSESSID=1@localhost:7869

That should make the server execute the script and your breakpoints should be hit.

Happy debugging!!!

Tags: , , , , , , ,

One Response to “Remotely Debugging PHP with Eclipse”

Great to know that doing this for PHP is possible.

 Feed for this Entry

Something to say?