Configuring MacGDBp for Debugging a Local Debian Virtual Machine

Sep 7 2010

In my current Drupal development environment, I run an entire Debian server stack (LAMP + Memcache + Varnish, etc) inside of a VirtualBox virtual machine. On those frustration-laden occasions when I need to fire up the debugger, I use MacGDBp to connect to the virtual machine. Here's how I configure them. (If you just want to configure MacGDBp for debugging with MAMP or OS X's Apache, you may want to read an earlier article, and then check out the updates for Snow Leopard. <!--break-->

Server Configuration

On my virtual machine, I am running Debian. The same instructions would also work on Ubuntu (though versions may be different.) I assume that you already have a full LAMP stack.

Install XDebug

To install XDebug on Debian, you probably are best just doing this (as root):

 # aptitude search php5-xdebug 
 # aptitude install php5-xdebug

The first line is just to make sure that it's there. It should show you whether or not that package is available. The second line installs it.

Configure XDebug

Next, we want to configure XDebug to send debugging information from our virtual machine to the host (the place I am running MacDGBp from). To do this, we need the IP address of the OS X host. I usually get it by opening a new console and typing ifconfig. Here, I'll assume that the OS X host has the IP of 10.20.30.40.

With this information, I am ready to edit the XDebug configuration file. On Debian (when debugging Apache), this is in /etc/php5/apache2/conf.d/xdebug.ini. Here's what the file should look like:

    ; Debian should have done this for you:
    zend_extension=/usr/lib/php5/20060613+lfs/xdebug.so

    ; Remote debugger features
    xdebug.remote_enable = On
    xdebug.remote_autostart = 1
    xdebug.remote_port = 9000

    ; Our host
    xdebug.remote_host = 10.20.30.40

Now Apache will need to be restarted:

  /etc/init.d/apache2 restart

We should now be ready to configure MacGDBp to receive debugging information.

Setting up MacGDBp

Assuming we configured the above correctly, all we should need to do now is start up MacGDBp and then point our browser at something on the server.

As soon as the server receives a browser request, it will start sending debugging info to the remote host and port we configured in the previous section. MacGDBp should be listening for that information.

Mapping local and remote files

To map the files on my local workstation with the ones on my Virtual Machine, I add Local/Remote paths in MacGDBp. This is done by going to the MacGDBp menu item, selecting preferences, clicking paths, and then using the + button to add a new path.

Local paths should look something like this:

  /Users/mbutcher/path/to/code

Remote paths should look like this:

  /var/www/path/to/code

Once you've configured this, you might have to restart MacGDBp to get this working.

That should have you off and running, using MacGDBp to debug on a virtual machine. XDebug is a powerful tool, though, and a read through the documentation can have you using an even more sophisticated environment.

Read More:



comments powered by Disqus