Remote Debugging of PHP with Komodo IDE on Mac OS X

I am doing development on Mac OS X 10.7, with Komodo IDE 6.1.3 using PHP and Apache, both installed from Macports.

I want to enable remote debugging of my PHP scripts running under Apache using Komodo.  Following instructions from Activestate’s website, I have configured my system as shown below to make it work.

I have already installed Apache and PHP using Macports, so I only needed to install php5-xdebug using the following command:

sudo port install php5-xdebug

I then added the following to the /opt/local/etc/php5/php.ini file:

;xdebug config
;the .so file is loaded under /opt/local/var/db/php5/xdebug.ini
;zend_extension=no-debug-non-zts-20090626/xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
;xdebug.idekey=<idekey>

Then in Komodo IDE, set the tcp port to listen for debugging connection as shown below:

When I wish to debug a script, I just add the following query to the end of the browser url for the script, and xdebug sets a browser cookie that turns on debugging for all scripts from that point forwards.  The query string to add is:

?XDEBUG_SESSION_START=1

To disable the debugging again, you just need to delete the cookie from your browser.  Using Firefox, go to the Privacy settings under preferences:

Then click on the “remove individual cookies” link, and type in “localhost” as the search criteria for the cookie.  This will show all cookies for the localhost where you are debugging, and you will see the XDEBUG cookie as shown below.

Simply click on the Remove Cookie button, and debugging is turned off again.

Remote Debugging via proxy with PHP, XDebug, and Komodo IDE

So I am experimenting with remote debugging using Komodo IDE, PHP and Linux.  Following instructions from the xdebug website, I typed:

sudo pecl install xdebug

Then I added the file /etc/php.d/xdebug.ini with the lines:

extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000

Running php -i, yields amongst others, the following message:

xdebug support => enabled
Version => 2.1.1

XDEBUG NOT LOADED AS ZEND EXTENSION

Supported protocols => Revision
DBGp - Common DeBuGger Protocol => $Revision: 1.145 $

All good so far. Now I need to set up the debugging proxy server on the webserver host so that multiple developers can debug scripts from the same dev webserver.

To do this, I followed the instructions provided by Komodo using their python-based proxy server:

export PYTHONPATH=/lib/support/dbgp/pythonlib;$PYTHONPATH
cd /lib/support/dbgp/bin
python pydbgpproxy -i 138.77.20.48:9001 -d localhost:9000 -l DEBUG

So now I have configured Komodo to use the proxy server for debugging.

Komodo debugger options

Now to initiate a debugging session with a website script, I followed the instructions provided by Komodo:

Click Debug | Listen for Debugger Connections

Then in the browser, enter the URL of the script and append: ?XDEBUG_SESSION_START=damo

Now Komodo asks to start a debug session where I click Yes, and …. The script completes and no debugging occurs. 😦

Seems more investigation is required here.

I am wondering whether the ajax calls in the script I am attempting to debug are confusing the proxy and or Komodo? Each ajax call will also have the cookie set for debugging and so there are multiple requests do debug with the same Komod instance. Perhaps this is why the debugger is not working.

I am hopeful I can get this working. Will save alot of time trying to find those nasty bugs.

Damien.

Macports: How to configure php5 for apache2

I guess I am spoiled with Redhat’s integration of all these packages where you simply install and away you go. Macports isn’t quite a polite in this regard. The default config files are incomplete and not enabled when it is installed.

So I have had to do some massaging to get php working.

The file /opt/local/apache2/conf/extra/mod_php.conf is missing some configuration parameters. I’ve changed mine to look like this:

<IfModule mod_php5.c>

AddType  application/x-httpd-php         .php
AddType  application/x-httpd-php-source  .phps

AddHandler php5-script .php
AddType text/html .php

DirectoryIndex index.php

</IfModule>

I specifically had to add the handler and also load the module. Then in the /opt/local/apache2/conf/httpd.conf file, I had to add the line: Include conf/extra/mod_php.conf as there wasn’t even a commented out line that would include this module.  Also in the /opt/local/apache2/conf/httpd.conf file, also need to add the line LoadModule php5_module modules/libphp5.so so that the php library is loaded into Apache.

A graceful on the server:

sudo /opt/local/apache2/bin/apachtctl graceful

and away we went.

Damien.

Addendum

Turns out that a message is printed at completion of the install, which was not apparent to me because I used a GUI to do the installation. The message states:

If this is your first install, you need to activate PHP in your web server.

To enable PHP in Apache, run
cd /opt/local/apache2/modules
/opt/local/apache2/bin/apxs -a -e -n “php5” libphp5.so

A useful tip I highlighted in a previous post helps to find this sort of information after installation.  This command simply adds a LoadModule option to the main httpd.conf file, but does not add the other configuration options above.  So you still need to make the above changes.