Any serious PHP developer should use a debugging tool. Applications are becoming more complex, using OOP, and spanning more files. This post will quickly bring you up to speed and give you the most awesome debugging tools on the planet.
I have been using Zend Server CE for local development. It has all the bells and whistles you need, and you can pick from 5.2 or 5.3. Zend Server CE comes with the Zend debugger, but I prefer to use XDebug. You can follow this tutorial to get XDebug working with Zend Server CE on OS X.
Once you have XDebug installed, you should see it listed in PHP info by calling
<?php phpinfo(); ?>
in a PHP script or
php -i
from the command line.
Configuring XDebug
Once you have XDebug working and you have restarted Apache, you need to add a few things to your php.ini file if you want to actually step through your code line-by-line. If you are using Zend Server CE, it is probably located at
/usr/local/zend/etc/php.ini
Add the following lines to your php.ini file under zend_extension (add lines in bold):
[xdebug] zend_extension="/usr/local/zend/lib/php_extensions/xdebug.so" xdebug.remote_enable=On xdebug.remote_autostart=On
Restart Apache again, and you can double-check php info to see the changes to remote_enable and remote_autostart were set correctly.
These php.ini settings allow debugging to start automatically in an external application, as you will see below…
MacGDBp – Debugging Software for XDebug
Users of OS X can install a program called MacGDBp to step through PHP code and debug variables. This application intercepts browser requests made to your application, and allows you to set breakpoints and debug your code much faster.
Windows users have a couple software options for xDebug, such as Ultraedit Studio, Komodo Edit, Aptana (although I have never got it working correctly with Aptana), Eclipse, et al.
With MacGDBp open, load a page from your web browser in a PHP application hosted on localhost, and your browser will look like it’s hanging (if you set up xDebug correctly). You should see the first part of your application code in MacGDP.
You can also add breakpoints by browsing to files with the breakpoint window. In MacGDBp, open Breakpoints by going to Window > Breakpoints or Shift + Command + B. Click the plus button to browse through your files.
Once the file appears in the breakpoints window, you can click line numbers to add breakpoints. Breakpoints will appear as blue arrows. At the time of this writing, clicking the correct line number was somewhat difficult for me, but it just takes some getting used to. The application will halt execution at your breakpoints after you click “Run” in MacGDBp.

Assuming the file you add is loaded during the page request, if you click “Run”, MacGDBp will let the browser request resume until it hits your breakpoint. From here, you can step in/out/over of functions. You can also browse variables and make sure they are being set properly.
If you need to step through the code again, click the “Reconnect” button on the top right in MacGDBp, and click refresh in your browser. You can also leave MacGDBp disconnected and develop your application normally until you need to debug again. When you reconnect macGDBp, it will then stop at the first line of code, allowing you to step through again or run to your next breakpoint.

Step In, Step Out, Step Over
When you start debugging a request with MacGDBp, you will be presented with the first executable line of code. At this point, you can determine how to proceed. If the line is a function, you can click “Step In” and MacGDBp will take you to the function being called.
While in that function, you will step through that function line-by-line. You can continue to step through functions called within other functions, which can get you lost in a hurry if you’re not careful. If you want to stay inside the current function, you can click “step over” at a function to go to the next line.
Stepping out will bring you back to the original code where you stepped into the current function originally. This is helpful if you accidentally step into a function and you want to go back.
Modifying UI
I recommend modifying the icons in MacGDBp, to include Icons and text. You can do this by right-clicking in the gray icon area of the application. You can select Icons and text, which makes it easy to understand the icons and what you are doing until you become a seasoned debugger.
![]()

I'm 
