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.

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.

Macports: How to install mod_perl2

When attempting to install mod_perl2, I received an error code 2. Very unhelpful error message, but after some googling, I found this bug ticket which explains what you need to do.

Essentially, you need to forcibly uninstall perl5.12 (or perl5.10) and then re-install with the threads variant:

sudo port -f uninstall perl5.12
sudo port install perl5.12+threads

Then you can install mod_perl2 with:

sudo port install mod_perl2

Not a particularly elegant solution, but nonetheless gets the job done. Hopefully this issue will be fixed in the future.

Damien.

Macports: Some useful tricks

I have decided to jump ship from Fink over to Macports.  Out of the frying pan and into the fire perhaps, but Fink’s packages just don’t seem to be kept up to date as well as Macports.  I’m keeping a close eye on brew as well, although I too am skeptical of its dependence on Apple packaged software, especially when it comes to OS upgrades.

Anyway, here are some very handy tips that I have discovered in my travels.

Post-installation instructions

Some packages provide instructions on installation completion.  At times you may have ingored them or used tools such as Porticus to do the installation in which case the instructions are lost in the scroll from all the dependencies that went along with it.  So, there are a couple of commands that you can use to get this vital information back:

This command looks at the notes for a package (if it has any):

sudo port notes $packagename

If there are no notes, you can look at the portfile directly using:

sudo port cat $packagename

You will probably see some instructions to be printed at the end of the script

How do I start or stop daemon processes

So this always frustrates me, and each packaging system does it differently. Macports wraps some scripts around the launchd system of MacOS 10.4+. So you can use the launchctl load -w /Library/LaunchDaemons/${packagename}.plist to do it. But a more convenient way is to use the load/unload option to the port command.

sudo port load $packagename
sudo port unload $packagename

Sadly, this not only starts and stops the daemon process, but also enables or disables auto-startup at the same time. You can do things separately, or at least not without knowing the individual package’s startup scripts.

As I come up with new tips and tricks, I’ll add them to this blog post.

Damien.