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.
UPDATE: As of my last login to Zend, the 5.5.1 download was available. I installed and everything worked well. Still using Netbeans but appreciated all the same.
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!
In this post, we will discover how to go about debugging a specific page in your website through setting up debugging in your MAMP stack, the free Netbeans IDE and your Firefox browser.
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 easy Xdebug. 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.)
Tip! You can also force Netbeans to not open your browser when you debug:
In your project properties (right click on the project -> properties), click on Run Configuration, look for the “Advanced…” button and set “Do Not Open Web Browser“. Click OK.
A big thanks to Leonard Teo for this tip.
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
The following screencasts cover making XDebug and Netbeans work together. It’s a recap of the text here with some added instruction on setting up an Apache virtual host for development from your computer. Please note, I do not have the ability to be concise when I speak and you may lose patience. My apologies up front. (If you want a condensed version, just watch Part 2 and than skip to Part 6. You might want to watch Part 5 if 6 leaves you scratching your head.) Also, as many people find when they listen to themselves recorded, I find that my voice and accent sounds kind of strange and annoying. That’s one part me and another part Southern Utah accent. Bear with me if you can.




Just wanted to thank you for a great explanation from a basic level of the benefits and pros of working with xDebug. I wish I would have learned to use this years ago
Thanks Jay,
Glad it actually came in handy for someone.
Thank you. This is just what I’m looking for
Hi Brett,
Thanks for all your time and effort putting this info together. I’ve struggled with Netbeans & XDebug in my new Mac (also a new “Mapple” convert) for days and your tutorial finally put everything into perspective.
Looking forward to all your future video tutorials!
Cheers,
Izzy
thanks alot that was very usefull thanks
Bret,
10/10
You get a perfect score! “Useful” is the mother of all understatements. I’ve been coding manually in textmate and debugging mostly in my head (you can imagine how reliable that is!). Your tuts have opened up a whole new avenue for me! while I’m not in love with NetBeans, there’s no question that after your screencasts it will take a prominent place at the forefront of my workflow.
See you on the forums @ CI
Oh, and PS: If you could put RESTful into the same eloquent, well spoken, understandable terms… You’d probably get something of a cult following!
Thanks @Daniel. Glad this was useful to you. It’s getting a bit outdated so hopefully you can get the more recent tools. The text content of the post is more up-to-date. I was thinking that another screencast might be fun. Thanks for giving me a great suggestion.
Hiya Brett!
I followed your tuts to a ‘t’, and with the exception of some updates to the tools (as you mentioned in your reply to my comments) it worked exactly as expected. I am particularly glad for those last 2 segments where you really tied everything together! It was quite a blur up to that point, but that cleared things up.
A follow up question or two, if I might:
- For some reason when I start debugging, while everything pretty much works as you’ve explained (connection, stepping-through, etc) the problem I’m having is that Netbeans only and repeatedly cycles through CI config-file, and that’s about it. It never makes it to any of the controllers, views, etc.
I’m wondering if you might shed some light on this?
Brett, nevermind!
Did some research and I guess Google likes me today.
If you’d like to get rid of that annoying 404 & get CI & Netbeans/Xdebug working flawlessly in under 15 seconds….
Add these 1 line to your config file & change another.
Have a look:
http://stackoverflow.com/questions/978325/enablequerystrings-not-working
TOP answer from Phil Sturgeon. The man’s a legend.
Great advice @Daniel. I never even thought to get rid of it because I always just ran it through the first time and left the debugger running after that. Perhaps I need to revise my post here because I believe I covered that in the post and the videos.
Hi guys,
Thanks a lot of the hard work, I really appreciate it..
I got Netbeans to show me the debug toolbar and the addon on mozila seems to be working fine,
The only issue I am having is that netbeans never comes to the break-point, I can see some values changing in the variables window (when I debug), which means ( i assume) the xdebug is working fine, but how can I get it to move to the break-point where I want it
I have followed all the steps suggested here, except the .htaccess file, as I did not know what to do with that or where to put it,
Any help would be highly appreciated, and thanks again..
Cheers
Hasn
Hi Hasn,
In case you haven’t resolved this yet…
Does it even break at the beginning of the script? It should pause your page so it seems unresponsive and you should get a green highlight bar on the first line of your index.php page. It is possible to hit F7 when the cursor is about to jump out of the current page. In this way. you can drill down all the way to the page you need to check. I say this because there is a possibility that you may not be getting to the break point in execution.
Finally, I had to actually download the MAMP source code and build a newer version of xdebug against it recently as I was having problems with newer versions of netbeans.
Good luck!
Great article and screencast too. Your voice is ok, at least to me. As I’m not english native speaker, i didn’t see nothing stranger or annoying in your voice
Just to know.
You can use VirtualHostsX on Mac to create virtual hosts (surprise).
It’s a very simple app that does what you teach in the Part 3.
Of course, what you said is correct. It’s just my 2cents
Netbeans it’s a great tool for developer. But, to me, it’s a little heavy. I always need to check the website on Internet Explorer, so Netbeans + Dreamweaver + Photoshop + Windows XP (on Virtualbox) my 4gb are too little
Today I’m using Coda + Photoshop + Windows XP (sometimes Windows 7 to test on IE9). And I’m happy with that. Sometimes I need to go back to Dreamweaver, it’s a ninja tool to create forms (inputs, labels, etc..) and tables. Just TAB and I have a new row
Regards
(sorry for my comment has nothing about Debugging)
Thanks Rafael! I would love top use Coda but I’m a bit too cheap to pay for anything that I can get for free. Thanks for your encouraging comments. Hope the tutorial helped.
VirtualHostsX is great, but again, not willing to pay for it. Once I installed it (to try it out) I pretty much had to start over with my customized MAMP stack. So be ware.