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:
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.
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 !!