Installing Xdebug on xampp for linux

As it’s commonly suggested, tweaking code while it still in development is foolhardy. If your code seems slow while it’s actually doing what it’s suppose to and right , the first is to measure its performance in actual values. It will just be a wasteful action to just try to tweak the code without these types of diagnostics.

A better measure that is accurate, sometimes that actually measure the time taken by a single line of code can be done using a code profiler. A profiler, typically implemented as an extension to the PHP runtime engine, records the delta between the start of a statement and its end, notes the delta between the start and end of a procedure, and captures the total time required to craft a response to an incoming request. With that, you can find the statement, loop, function, class, or library that is slowing down the application. A better profiler could also measure processes memory usage if process time is not the problem.

Xdebug is my preferred profiler for PHP, which also provides stack trace information to debug PHP applications. It generates datafile that can be viewed using KcacheGrind.

Building and installing Xdebug

I will be using a lamp stack based on xampp for linux installed on ubuntu hardy. I here assume you have already installed xampp for linux and put the bin folder in your environment path.

If you have not yet put the bin folder “/opt/lammp/bin” in your path, run at the command prompt

$ export PATH=/opt/lampp/bin:$PATH

if you would like to have that bin folder inserted in your path every time you login

edit the file .bashrc located in your home folder (ubuntu) for other distro it is .bashprofile

$ sudo gedit /hone/salimane/.bashrc

and add at the end of the file

export PATH=/opt/lampp/bin:$PATH

and save it

Download and unpack the tarball, and change to the subdirectory of the source code. Ensure that phpize and php-config are in your shell’s PATH, and prepare to build with phpize.

$ wget http://www.xdebug.org/files/xdebug-2.0.3.tgz

$ tar xzf xdebug-2.0.3.tgz

$ cd xdebug-2.0.3/

$ phpize

Configuring for:

PHP Api Version:         20041225

Zend Module Api No:      20060613

Zend Extension Api No:   220060519

$ ./configure

$ make

$ sudo make install

Installing shared extensions:     /opt/lampp/lib/php/extensions/no-debug-non-zts-20060613/

Notice the directory emitted in the last step. You’ll need it in the next step.

Configuring Xdebug

After the Xdebug extension is installed, you’re ready to enable and configure the extension.

First create a folder in your temp folder that will holds the data file generated by Xdebug

$sudo mkdir /opt/lampp/tmp/xdebug

$sudo chmod a+rwx -R /opt/lampp/tmp/xdebug

Open php.ini in a text editor, and add the following lines.

zend_extension = /opt/lampp/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so

xdebug.profiler_output_dir = "/tmp/xdebug/"

xdebug.profiler_enable = On

The first line, zend_extension, loads the Xdebug extension. Notice the same directory as the one you noted before. The second line names the directory to place the profiler output. (the one you just created). The third line enables the profiler.

After adding the lines and verifying that your output directory is writable, restart your Web server.

http://localhost/xampp/

click on phpinfo()

Scroll down to the Zend logo, Xdebug should appear next to the logo if Xdebug has been properly loaded and configured.

10 Responses to “Installing Xdebug on xampp for linux”


  1. 1 Zergus December 17, 2008 at 3:28 pm

    Excellent!
    Worked as a charm. Thanks for installation tips.

  2. 2 Eric Sender February 20, 2009 at 6:07 pm

    Hey thanks for the guide, but I think I hit some kind of road block with “phpize”

    I am running LAMPP 1.70, I did the export PATH=/opt/lampp/bin:$PATH command, then when I typed in “phpize” I get the following:

    eric@eric-lunix32:~/Desktop/xdebug/xdebug-2.0.4$ phpize
    Cannot find config.m4.
    Make sure that you run ‘/opt/lampp/bin/phpize’ in the top level source directory of the module

    Any help with that?
    Thanks

  3. 3 Salimane Adjao Moustapha February 20, 2009 at 6:21 pm

    Hi Eric,
    are you sure you installed the devel version of lampp 1.7 ?
    make sure u followed the steps in http://theindexer.wordpress.com/2008/06/02/installing-a-lamp-stack-on-linux-using-xampp-for-linux/
    Thanks :)

  4. 4 Eric Sender February 20, 2009 at 6:32 pm

    Thanks for the fast reply. It turns out it was in the xdebug-2.0.4/xdebug-2.0.4

    So now phpize does execute, but I get the following bad news :(

    eric@eric-lunix32:~/Desktop/xdebug/xdebug-2.0.4/xdebug-2.0.4$ phpize
    grep: /opt/lampp/include/php/main/php.h: No such file or directory
    grep: /opt/lampp/include/php/Zend/zend_modules.h: No such file or directory
    grep: /opt/lampp/include/php/Zend/zend_extensions.h: No such file or directory
    Configuring for:
    PHP Api Version:
    Zend Module Api No:
    Zend Extension Api No:
    Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF
    environment variable is set correctly and then rerun this script.

    eric@eric-lunix32:~/Desktop/xdebug/xdebug-2.0.4/xdebug-2.0.4$

    I’ll check out the devel version, I am not sure if that is what I have installed (though I can confirm that I do have phpize)

  5. 5 Salimane Adjao Moustapha February 20, 2009 at 6:40 pm

    Hi Eric,
    I think you don’t have your essential tools for compiling from sources. if you are on ubuntu , you can try :

    sudo apt-get install build-essential checkinstall cdbs devscripts dh-make fakeroot libxml-parser-perl check avahi-daemon

    Thanks

  6. 6 Eric Sender February 21, 2009 at 5:33 am

    Okay the installation worked (apparently) it took a few minutes and seemed to end gracefully.

    But I get the same error when doing “phpize”…

    I saved the entire output of the compiling sources (in case you woul dlike to view it) Do you think XAMPP 1.70 is just bad or something?

    FYI: I am using Ubuntu 8.10 32bit on a virtualbox with Windows Vista Business 64bit as the Host OS.

    I really appreciate the help you are giving!

  7. 7 Salimane Adjao Moustapha February 21, 2009 at 9:40 am

    Hi,
    make sure you have installed the development package of XAMPP for Linux 1.7

  8. 8 Eric Sender February 24, 2009 at 5:25 pm

    I feel pretty embarrassed, but yeah you’re right. The phpize worked and xdebug works too.

    Thanks for sticking with me!!

  9. 9 Salimane Adjao Moustapha February 24, 2009 at 9:55 pm

    it’s a pleasure to know that everything works on your box :)


  1. 1 Debugging With Xdebug on xampp for linux « The Indexer Trackback on June 17, 2008 at 11:26 am

Leave a Reply