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:

[ZendModules]
zend_extension=/usr/lib/php5/20060613/xdebug.so
xdebug.remote_enable=1 
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=your mac's ipaddress or localhost
xdebug.remote_port=9000

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 xdebug.so 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 

 

Conclusion

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.