Debugging PHP on a Mac with Netbeans

2

Posted on : 07-11-2009 | By : Brett | In : CodeIgniter, Mac, Netbeans, PHP, Programming

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.

Xdebug Helper for Firefox

Xdebug Helper for Firefox

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

Xdebug in php.ini

Xdebug in php.ini

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 debug button

netbeans debug button

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.

Xdebug Helper Toogle Icon

Xdebug Helper Toogle Icon

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

 

Part 6: Wrapping up by showing a few features of debugging with xdebug in Netbeans

I’m a “Mapple” Person!

0

Posted on : 27-08-2009 | By : Brett | In : Bretticus, Humor, Mac, Technology

I made the Switch

I’ve jumped in! I’ve slipped on the proverbial black turtleneck. Yes, I’m a switcher!

About a month ago I decided that my large, hot lead-brick-of-a-laptop, otherwise known as my HP Pavilion ZD8000, was getting a bit “long in the tooth.” On a hot July day, in my air-conditioned home office, it decided to to test my patience by overheating and shutting off without warning in approximately 10 minute intervals. My only thought, “Time to ship this sucker away!” Fortunately, my “brick” belonged to my employer. So, I asked for a new laptop; and I asked for a MacBook Pro!

This all started several years back when my office was in a building with my fellow employees and not in my house. You see, that office was chuck-full of Windows, but I decided I wanted to use Ubuntu exclusively at work. At that time, I wore two hats (and still do to a certain degree.) I moonlighted as a network admin while I wrote web code for most of the day. The vast majority of my code was PHP so Windows wasn’t all so necessary (yes, I had to reboot into XP once in a while to crank out a .NET app or two.)
I got to where I could pretty much do everything I needed with Ubuntu Linux. It was great for running a LAMP stack and many of my net admin tasks were done at the console. It was a great fit for me. I used it exclusively for several years, and then I moved.

I started telecommuting in late 2007. I turned in my Dell for a shiny new brick. It came with Windows on it. I promptly dual booted Ubuntu into it and it became a permanent fixture in my home office. Immediately, I had issues with my USB headphones and sound in Ubuntu. Since my Skype account became my work PBX extension, I found myself selling out and moving back to Windows to avoid the headaches associated with intermittent sound issues in Linux. In fact, I just started using my brick as a LAMP server (Ubuntu Desktop) and developing in Windows from my very own desktop pc. That was about the time I realized that a Mac might be a good compromise for me. Now that I’ve used it for few weeks, I couldn’t be happier with the combination. Thanks to helpful utilities like MAMP, I have a full LAMP-equivalent *nix stack on my Mac with all the niceties of a proprietary GUI. Finally, I could roll two computers into one for development and administration duties.

Over the next few months, I’ll be writing about my setup for PHP development on my MacBook Pro and why I chose the setup that I did. I’ll be including tweaks, etc. that I have implemented to customize my experience. (Let’s be honest, my record would indicate this Mac writing will not happen for awhile so, please, don’t hold your breath. Sorry.)

Impressions

The first day I booted my new, shiny MacBook Pro (actually, it was used and a couple of years old. but “new and shiny” nonetheless ), I felt like I had lost several million brain cells and devolved into a Neanderthal. Apparently, Apple had decided that they invented the personal computer and, as years went by, to stubbornly hold onto their “crazy” keyboard configuration. To make me feel even more like a newbie, a certain suspicion that I had carried around for many years proved untrue. Ubuntu currently chooses gnome for it’s default GUI interface. Since gnome shares many similarities with Windows, I must admit, using Ubuntu had not prepared me for using a Mac as I assumed. I stumbled for a few days getting it set up just right to work for me. Finally, After a week or two of rewiring my brain to use the Alt key instead of the Ctrl key (I needed to use my PC keyboard because Apple keyboards seem to suck,) I finally felt “OS ambidextrous” enough to forge on.

One of the surprising things about Mac was how closed it felt compared to Linux or even Windows (As I get more familiar with the ins-and-outs of OSX, that perception  diminishes somewhat.) For example, it seems that all the option settings for Mac applications were, “I’m an idiot, just do it your way” and…well, that’s it. Apple does tend to make their software “blunt and to the point” (much like an Apple boardroom meeting I’m sure.) I do appreciate the rock-steady stability of OSX.

The hardware is just beautiful. It’s silent, cold, and light. It really is art and elegance. I do “dig it.” I have not started worshipping  it yet however.

Mapple People

I have gotten many compliments from several Mac users of my acquaintance and also in online communities. To my new status as a “switcher”, I typically get something like, “Welcome to the fresh, clean Apple air outside of the putrid, stinky torture-chamber-of-a-deep-dark-dungeon called Windows that you languished in all your life!.” … Wait a minute??? I still use Windows 7 (love it)  from time to time and there are still some things about OSX that drive me nuts! I must say, I do not want to be counted among the turtle-neck wearing fan-boys that have a hissy fit the instance Apple is criticized in any way, shape, or form (tune into MacBreak Weekly for examples.) The Mac culture is sort of weird (and I’ve thought so for years.) The “true believers” seem to be a throwback of the fringe-clad culture of the 60s. Apple has indeed encouraged it. I personally feel there are better things to get zealous about than whether or not you have a half-eaten piece of fruit icon opposite your screen. I’ll just take OSX as a  very nice *nix-based OS that I can use comfortably for network administration and development. Thank you very much!

(of course the real reason I posted was to show these two hilarious videos on mac culture.)

The latter video is even more hilarious if you’ve seen this original 1984 Apple ad.