Enable Xdebug on PHP development

Xdebug is crucially important for PHP stack trace debugging.

Here is what I have done to get started.

  1. Install Xdebug in ubuntu,
    sudo apt-get install php5-xdebug
    
  2. Modify php.ini to activate Xdebug
    ; file of /etc/php5/fpm/php.ini
    [xdebug]
    zend_extension="/usr/lib/php5/20121212/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
    
  3. Restart the webserver
    sudo service nginx restart
    

On a separate note, for an important feature, now we can call the function,

    // stacktrace debug till the calling point
    var_dump(xdebug_get_function_stack());

    // stacktrace printing message till the calling point
    xdebug_print_function_stack( 'Your own message' );

Thess functions will find out all the trace back for current calls.
First one will display every parameters within it. Extremely useful for debugging through large codebase.


Or follow the instruction on Xdebug. (Cited from Xdebug)

Instructions

Download xdebug-2.3.3.tgz
Unpack the downloaded file with tar -xvzf xdebug-2.3.3.tgz
Run: cd xdebug-2.3.3
Run: phpize (See the FAQ if you don’t have phpize.

As part of its output it should show:

Configuring for:

Zend Module Api No: 20121212
Zend Extension Api No: 220121212
If it does not, you are using the wrong phpize. Please follow this FAQ entry and skip the next step.

Run: ./configure
Run: make
Run: cp modules/xdebug.so /usr/lib/php5/20121212
Update /etc/php5/fpm/php.ini and change the line
zend_extension = /usr/lib/php5/20121212/xdebug.so
Restart the webserver