Welcome Guest, Not a member yet? Register   Sign In
Setup Netbeans & Xdebug for debugging CodeIgniter with Firefox [in under 15 minutes!] - Mac OSX
#1

[eluser]stormbytes[/eluser]
Hello,

After trying forever to get Netbeans to play nicely with Xdebug & CodeIgniter, I finally got it to work. Boy was it worth it. Gone are the days of 'test_controller' filled with 'echo' & 'prin_r' statements, or the globals-guessing-games. Now I can see pretty much any value, break on specific lines, add watches, and lots more. Plenty of Netbeans & Xdebug goodness all under one roof (well.. browser).

So I decided to share my spoils on the CI forum, in case others might benefit from the knowledge. What follows is a basic tut on how to get Netbeans/FireFox/Xdebug & CodeIgniter all working nicely together, and in under 15 minutes. No brains required. Just follow the steps and presto! You'll be debugging in no time.

Caveat: I'm a Mac user. While I expect the process to be similar on Windows, I have absolutely no clue how to go about it. Sorry Windows users... Buy a Mac Smile


Stuff You Need To Do::

1. Download/Install Xdebug Firefox Add-on

Start by downloading & installing the Xdebug add-on for FireFox, which at this writing stands at version 1.4.

- Go to FireFox->AddOns

- choose the 'Get Addons' tab and enter 'Xdebug' in the search field.

- Choose 'Add to Firefox' and you're good!

If you're too lazy to go through all that trouble, you can grab it directly from https://addons.mozilla.org/en-US/firefox/addon/58688/


2. Edit CI Config File

Next you'll need to make two small changes to your CodeIgniter config file (/application/config/config.php).

(taken from Phil Sturgeon's post on StackOverflow)

Open config.php, and find the line that says:

Code:
$config['enable_query_strings'] = FALSE;
and change it from "FALSE" to "TRUE".

Then find the line that says:
Code:
$config['uri_protocol'] = "AUTO";
Change it so that it reads:
Code:
$config['uri_protocol'] = "PATH_INFO";

Just in case I do something wrong, I opt to comment out the original lines & append the new ones directly bellow, like so:

Code:
// Original: $config['uri_protocol'] = "AUTO";
$config['uri_protocol'] = "PATH_INFO";

// Original: $config['enable_query_strings'] = FALSE;
$config['enable_query_strings'] = TRUE;

Okay, almost there!


3. Enable Xdebug in Mamp Pro's Php.ini files:

As I mentioned, I'm a mac user, and yes - I'm better then you for it! (Okay just kidding!).

- Lauch Mamp Pro (You can download a 14-day free trial from http://www.mamp.info/en/downloads/index.html)

- Choose File->Edit Template-> Choose the Php.ini file for whatever PHP version you're running.

- Scroll to the bottom of the file (or nearly the bottom?) and remove the semicolon ; from the beginning of this line:

Code:
[xdebug]
;zend_extension="/Applications/MAMP/bin/php5.2/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so"

- Then, add the following 4 lines below it, so that the block looks like this:

Code:
[xdebug]
zend_extension="/Applications/MAMP/bin/php5.2/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so"
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remotehost=localhost
xdebug.remote_port=9000

NOTE: The PATH above (/Applications/Mamp/bin/etc...) is my own Mamp/App path and yours may vary. That's perfectly fine.

4. Finally, with FireFox open, launch Netbeans & go to Preferences, and the PHP tab. Make sure that 'Debugger Port' is 9000, and 'Session ID' is netbeans-xdebug.


5. **OPTIONAL/SEE-FOR-YOURSELF**

I don't know if this step is critical, but I thought I'd include the text of my .htaccess file (it's a plain text file, named .htaccess that sits in your application root folder and contains config-info that Apache works with. Mine (code pasted below) simply eliminates the index.php part of the URL by redirecting all http-requests to index.php - don't know much beyond that sorry!)

Code:
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1

That's it! You made it.

Now setup (or open) your NB CI project of choice, and hit command+F5 or 'debug project [name]' from the debug-menu. A new Firefox window (or tab) will launch with your project/site/app in it, and Netbeans will say 'netbeans-xdebug + running' in the bottom/right corner of the window.


*** It will seem like the site/web-page is 'hanging' but in fact it's waiting for YOU to proceed, controlling every step of the process through the debug toolbar (or keyboard shortcuts). Go back to Netbeans and hit F7 to step through the process or F5 to run uninterrupted.

Hope this helps!

If there are errors in this post or if I've left anything out, please feel free to comment below so others might benefit. Personally, I don't know much about this beyond what's in this post, but if you post questions and I can help you I'll give it a shot!


----------------------
Edit -

PLUG: This post was inspired by "Brett" (aka: 'Bretticus') who created a fantastic introduction screencast (series) to debugging with Nebtbeans & Xdebug. If you'd like to see this in action and learn more about what you can do with debugging, check out the tuts on his site:

http://brettic.us/2009/11/07/developing-...-netbeans/


Messages In This Thread
Setup Netbeans & Xdebug for debugging CodeIgniter with Firefox [in under 15 minutes!] - Mac OSX - by El Forum - 10-28-2010, 07:52 PM



Theme © iAndrew 2016 - Forum software by © MyBB