Debugging CodeIgniter Project using Xdebug and Netbeans

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 😀 ]

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

Advertisements

PHP extension path confusion in Uniserver

I have been using uniserver for over approximate 1 year now. I was so happy with it. Today we faced a problem while we were trying to activate cURL in uniserver.

Here is the sceneario:

uniserver 3.5 Apollo  : Apache(2.0.59 ), PHP(5.2.3)

In my Laptop i was running uniserver not as a service. But in our real IP server machine we were using uniserver as a service.

When i went to activate cURL in my Laptop i followed this :

  1. downloaded the php 5.2.3 from php.net
  2. i copied the php_curl.dll into ‘/usr/local/php/extensions’ folder
  3. and libeay32.dll and ssleay32.dll into ‘/usr/local/php/’
  4. then i removed the comment from php.ini for php_curl.dll

Then i run a test.php which uses curl_init() and it worked fine.

I tried to follow the same procedure in our server machine bt this time curl failed to load. And we had no idea why it did not worked. Then we tried combination/permutation :))  copied 3 dll into windows/system32  and other way. But all failed measurably.

Then we start looking for the reason. Then i stumbled upon  a uniserver forum topic where someone suggested to copy libeay32.dll & ssleay32.dll into Apache2/bin folder. And this time it worked fine.

Now, we have to dig for the reason. why this happened to us?? Today i found this

http://www.usenet-forums.com/php-general/51812-php-extension-path-confusion-under-apache-xp.html

where they faced such problems for openssl and the reason explained. here i am quoting the magnetic part of the topic:

The php directory must be in the env path of the Apache2 service
(e.g. in the system path) or else some php extensions will mysteriously
fail to load.

I hope this comes helpful for others.