After nearly two months of using OS X, I think I have finally found my groove when it comes to doing my job. That is, writing code for websites, mainly in PHP.
For many years prior to using a Mac for PHP development, I had been using Windows or Linux and Zend Studio 5.x. When I was looking several months back for the Mac version download for my Zend Studio license, I was presented, instead, with a free upgrade to version 6. Wow, that was nice Zend! Unfortunately, the version I paid for (the “perpetual” license) was no longer there to download. But hey! I got the brand-new version. That’s great right? Wrong! Zend decided to drink the Eclipse Kool Aid and completely changed an IDE that I had grown accustomed to (I guess it’s only fair to point out that Zend Studio 5.x was so old at this point that it was getting increasingly more difficult to install on more modern operating systems and newer java platforms.) In spite of the seemingly “over-bloat” of Zend Studio 6.0, I decided to give it a try. I must say that everything just felt wrong. Now I’m sure there are many PHP developers out there that have been using Eclipse for years and can’t live without it, but I just couldn’t seem to make it work my voodoo. I didn’t have the patience to get my Eclipse PHD, so I went looking elsewhere. That led me to a surprising alternative: Netbeans. Although very similar to Eclipse, an IDE with modules/plug-ins for multiple computer language support, Netbeans (entirely free) impressed me right on the spot. I know Zend Studio has all the same features more or less, but the way Netbeans is put together just seemed more natural to me (things I wanted to do actually worked.) Let it suffice to say that I have been using Netbeans since then and I haven’t looked back!
Setting up Debugging with Xdebug and Firefox
In order to leverage the new-found versatility or MAMP, I needed a good debugger. I had had a pretty decent debugger with Zend Studio 5.x and that would be an essential requirement for netbeans. One of the cool features of Zend Studio was the integration of the Zend Toolbar with the debugger. Fortunately, this can be done with netbeans also, but you have to get a firefox plugin called Xdebug Helper. When you get it, note that it has one configuration option you need to set: Xdebug.idekey needs to be set to netbeans-xdebug.
Since I was using MAMP, I needed to install the xdebug extension for PHP. I actually downloaded the source and built the extension (used Xcode tools to phpize the source and build it and then just copied it to the appropriate MAMP folder.) I wish I had taken the time to record the steps involved, but instead I’ll just refer you to the easy way. Now we just need a little change in our php.ini file and we are good to go:
Note: As of MAMP version 1.8.4, there is an xdebug extension that comes with MAMP (just be sure to disable Zend Optimizer since they don’t seem to play well together.)
; Xdebug config for Mac OS X and NetBeans IDE
zend_extension=/Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20050922/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
Now, all we have to do in order to debug is evoke the debugger in netbeans. I do this by clicking on the debug project button in the netbeans toolbar:
Netbeans will open up your development website according to the URL you submitted when creating the project (make sure firefox is your default browser and that you have set the default page in your project.) Often, just clicking the button will automatically activate the Xdebug Helper addon for me. But if you want to make sure that netbeans debugs the URL in your browser, be sure the click the X in your firefox footer bar so that it changes color from gray to green.
Netbeans will open your startup page to something like:
index.php?XDEBUG_SESSION_START=netbeans-xdebug
If you are using a PHP framework like Codeigniter, the URL can be a little annoying at first. I have found that I only need to press the continue button to let the start page run it’s path and then just close that tab. From that point I just leave the debugger running and toggle the Xdebug Helper “X” icon when I need to debug any page that I am working on. Couldn’t be easier!
Screencast Tutorials
Part 1: Prerequites for Xdebug and PHP on a Mac
Part 2: Setting up XDebug Helper
Part 3: Setting up an virtualhost apache environment in MAMP for codeigniter
Part 4: Starting to use XDebug in Netbeans
Part 5: Debugging with Netbeans and XDebug




2