Debugging CodeIgniter Project using Xdebug and Netbeans

12 Feb

Finding the right way to debug PHP projects has always been a hot topic. Primitive solutions like `echo`, `print_r`,`var_dump` has always been the power tool :) for my type of ppl .  Let us forget those painful nights and go to a quick debugging solution with Xdebug and Netbeans 6.8; in a 1-2-3 step guide for CodeIgniter.

What i am expecting from you:

  • You already have a running web server [ Xampp/WAMP/ Uniform server ]
  • You know how to install Netbeans IDE 6.8 or it’s already running in your environment
  • You know what is CodeIgniter
  • You are not a complete Newbie

# STEP – 1

First add extension Xdebug in PHP. Download latest stable Xdebug version from Xdebug.org. Follow the procedures. If you are lazy like me and don’t want to read the whole thing [it's a bad habit :) ] copy the following settings and put at the end of your php.ini by not forgetting to change the path :)

zend_extension_ts="C:/wamp/bin/php/php5.2.9-1/ext/php_xdebug-2.0.4-5.2.8.dll"
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000

Note: If anything messes up later; come back and study those links over and over till u understand the whole thing.

# STEP – 2

Configure CodeIgniter to accept ‘?XDEBUG_SESSION_START=netbeans-xdebug’. You can follow one of my post or check in codeigniter forums for accepting GET data in CodeIgniter.

Start Netbeans IDE. Goto Tools >> Options >> PHP >> General: and check for settings in Debugging section. By default the port should be 9000 and Session-ID ‘netbeans-xdebug’.

#STEP -3 [ FINAL :D ]

Let’s say, You have installed a ‘test’ CodeIgniter application in your web server. Now add that application as a project in Netbeans 6.8 . Goto Project properties by right clicking on the project ‘test’.  Now go to ‘Run Configuration’ and click ‘advanced’  select ‘Ask Every time’ in Debug URL.

Now Open your ‘welcome’ controller and press ‘Ctrl+F5′ which will request for the URL:

specify url

insert ‘http://localhost/test/’  and press ‘Ok’.  Next select `Server side PHP`.

Clicking in ‘Debug’ button will open ‘http://localhost/test/?XDEBUG_SESSION_START=netbeans-xdebug‘ In you default web browser.

Now check in status bar for:

And check in toolbar for:

If those 2 shows up then u have successfully installed Xdebug+Netbeans. Your IDE is ready to do some debugging. Take your cursor over a line on index function of welcome.php; press ‘F4′ this will execute php scripts till that cursor. Dont worry if index.php is opened up focusing on first line.

Now You can watch for variables or step into functions or step over. You can check your code line by line.

Read this link which have brief discussion on what options you have for Debugging :).


My counting on steps could be wrong :) .. bt it looks nice 1-2-3. I tried not to explain a lot; so for more details study provided links.  I hope this will make your life more easier. Enjoy !!

About these ads

12 Responses to “Debugging CodeIgniter Project using Xdebug and Netbeans”

  1. rajj.. May 27, 2010 at 6:34 am #

    Excellent………..

  2. Awnish Kumar June 30, 2010 at 5:04 am #

    We are a web development company and is developing websites for more than 5 years and was looking for these type of debugging software. It helps me to debug the code and hence we are now faster than earlier

  3. tohin June 30, 2010 at 8:59 am #

    Good to know that it helped you…. :) .. best of luck :D

  4. Goody July 2, 2010 at 1:37 pm #

    Debug process works… at least Step Over/Into/Out. For some reason “Continue” doesn’t bring me to next breakpoint (should it bring me?). “Run to cursor” doesn’t work too… but that is not the main problem for me..

    Here is the main problem:
    In the end of the debug process browser pops up 404 error
    “404 Page Not Found
    The page you requested was not found.”

    Here is CI log message
    “ERROR – 2010-07-02 12:52:06 –> 404 Page Not Found –> local/XDEBUG_SESSION_START”

    Any ideas?

    Thanks in advance!

  5. tohin July 3, 2010 at 9:42 am #

    Seems your URI is not working : if you are trying to access the Controller’s INdex function then put the complete url as : http://localhost/test/controller/index/?XDEBUG_SESSION_START=netbeans-xdebug

    Let me know .. how it turns out ..

  6. Goody July 5, 2010 at 9:51 am #

    Thanks. It works! A bit strange but works.. maybe that is because I am using debugger at first :)

  7. Daniel October 28, 2010 at 10:56 pm #

    Hey

    Followed your tutorial. The explanation’s pretty good but unfortunately I’m still getting the same old 404 page at the beginning of debug and for some reason NetBeans debugger only cycles through my config.php page (ci config file) and that’s it.

    I’m on Mac OSX, debugging with Xdebug in FF3.6, NB latest vs. using Mamp. The debugger *is* working, but not ‘doing anything’ :)

  8. tohin October 29, 2010 at 7:35 am #

    At present in my office i am using MAC :).. so will give it a go.. If that works i will email you.

  9. Daniel October 29, 2010 at 8:04 am #

    tohin -

    Thanks for offering :)

    Actually I’ve found the perfect solution, and it doesn’t required a tenth of the work described in this post. Now this may be my own ignorance talking, as I don’t entirely appreciate the impact of the steps suggested, or perhaps the post/suggestions are outdated? Regardless, all I can say is that it took me exactly 5 minutes, start-to-finish.

    Netbeans works flawlessly with Firefox/Xdebug. No 404′s, no problems, no hassles. The debugger cycles through the code perfectly! Oh and rather then selecting the run/debug “Ask Every Time” option, you can simply turn it off altogether. That way it doesn’t recreate a browser tab every time you start/stop a session, and you can easily suspend/continue debugging from the Xdebug button within Firefox.

    After spending countless hours getting this stupid contraption to behave, I figured another 2 wouldn’t hurt. So I sat down and wrote a detailed post describing each and every step, start-to-finish, from scratch. And from some of the follow-up replies (from more knowledgeable/Windows folks) it seems that it applies just the same to Windows.

    If you’re interested, have a look:

    http://codeigniter.com/forums/viewthread/171833/#817810

    Thanks for the offer! :)

  10. tohin October 29, 2010 at 10:11 am #

    That’s a better solution. If an addon removes the repetitive tasks so why should we not use that. Thanks for the comments and thread. Will give it a go for sure.. Thanks .

Trackbacks/Pingbacks

  1. Code Igniter 2.0 Debugging with Netbeans 6.9.1 | Dice and Brackets - March 28, 2011

    [...] with coding PHP frameworks is setting up xdebug to work correctly with your IDE. There have been methods in the past to get CI to work with xdebug since code igniter by default clears out the GET global array which [...]

  2. Bookmarks « rafiq7s - January 9, 2012

    [...] Debugging CodeIgniter Project using Xdebug and Netbeans [...]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: