Setting up debugging with Komodo IDE and xdebug (and virtual machine)

Debugging with an IDE like Komodo (or another debugging tool) will save you a whole world of pain. It will save you through dropping in print_r all over you code and allow you to step in and out of your code as it executes with ease. The first stage, of course, is setting it up and that is the focus of this tutorial. 

The Environment

 I use a Mac, but run a virtual machine with Linux (Ubuntu Server). I mount the files using NFS. The steps in this tutorial will work equally well if you run Linux natively. If you do not run Linux at all, you will need to adjust some of the steps.

Installing xdebug

First we need to install xdebug with the following command:

sudo pecl install xdebug

Now we need to add some code to the php.ini.

sudo nano /etc/php5/apache2/php.ini

Add the following to the bottom of the file:

xdebug.remote_host=your mac's ipaddress or localhost

You will need to check to ensure the zend_extension path is correct:

cd /usr/lib/php5 

ls -la

Do you see 20060613? If not, there should be another folder with a set of numbers. Change directory into that to sure is there and use that folder name instead of 20060613. What you put in xdebug.remote_host will depend on whether you are running Linux in a virtual machine or not. If you are, add your Mac's IP address. If not, add localhost.

Reload apache:

sudo /etc/init.d/apache2 reload

Setting up Komodo

Go to Preferences and then Debugger.

Komodo Debugger Preferences 

At this stage, we want to ensure that the debugger breaks on the first executable line. This is important for mapping the URI's, which we will do in a sec (required if running in a virtual machine).

Initial break behavior: Break on first executable line

Komodo break first executable 

Preferences -> Debugger -> Connection: Komodo should listen for debugging connections on: a specific port: 9000


In the main Komodo menu, we need to tell Komodo to listen for debug connections. 

Debug -> Listen for debug connections: Select this. 

Komodo Listen Debugging 


First debug session

Go to the page you want to debug. It would be best to go to the home page of the project you want to debug. Append the URL with: ?XDEBUG_SESSION_START=1. This will start the debug session. You will get a dialog box stating a remote application has requested a debugger session, would you like to debug now. Click yes.

If you are running Linux in a virtual machine, you should be asked to map to the file. You need to navigate to where the actual file is. If you have mounted the files (using NFS or similar), then select local, navigate to the mounted folder and then the correct file in your virtual machine. It would be best to map the root of the project rather than individual files. 

Break points behaviour

In one of the previous steps I asked you to ensure that the debugger will initially break on the first executable line. You can leave it like that if you want, but you may prefer it to only break on break points that you specify. To change it, go back to Preferences and then Debugger and change the initial break behavior to "Run to first break point".  

Preferences -> Debugger: Initial break behavior: Run to first break point 

Komodo break on first line 



Hopefully this has helped you set up debugging on Komodo using Xdebug with a virtual machine. In a future tutorial, I will walk through some examples of how to actually perform the debugging.



Do you still use WeBuilder or kave you switched to komodo? I am looking at choosing an IDE for PHP - looking at Netbeans v/s Komodo

Blair Wadman's picture

I have switched to Komodo IDE. I had switched from Webuilder to Netbeans a while ago and really liked Netbeans. But I find Komodo even better. It is faster and slicker than Netbeans. Although Netbeans does some things better, like its SVN integration.

I can't use WeBuilder anymore anyway because I no longer use Windows.

Thank you kindly for sharing this!

Your tutorial page was very helpful. Thanks for your time to create it! I got going with debugging PHP using Komodo with your help.

Add new comment