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.

About these ads

~ by Salimane Adjao Moustapha on June 11, 2008.

18 Responses to “Installing Xdebug on xampp for linux”

  1. [...] Blog « Installing Xdebug on xampp for linux [...]

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

  3. 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

  4. 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 :)

  5. 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)

  6. 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

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

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

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

    Thanks for sticking with me!!

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

  11. Hi,
    thanks foy your indications.
    I had this problem; grep: /opt/lampp/include/php/main/php.h: No such file or directory.
    I resolved it with download xampp dev package and then I moved directory “include” of dev package in mail directory of xampp “/opt/lampp”.
    Ciao

  12. To compile xdebug for XAMPP 1.7.1 yo will need the Xampp Development Package which is broken for 1.7.1 (php.h and other *.h are corrupt).

    So this is a workaround:

    download php 5.2.9 and extracted if into into :
    -/opt/software/php/php-5.2.9
    -cd /opt/software/php/php-5.2.9
    then
    ./configure
    ./make
    ./install

    then
    download xdebug-2.0.5 and extract into :
    /opt/lampp/software/xdebug-2.0.5/xdebug-2.0.5

    cd /opt/lampp/software/xdebug-2.0.5/xdebug-2.0.5 #
    /usr/local/bin/phpize
    /opt/lampp/software/xdebug-2.0.5/xdebug-2.0.5 # ./configure –enable-xdebug –with-php-config=/usr/local/bin/php-config
    ./make

    this compiled OK and created xdebug.so under:
    /opt/lampp/software/xdebug-2.0.5/xdebug-2.0.5/modules

    copy xdebug.so under :
    /opt/lampp/lib/php/extensions/no-debug-non-zts-20060613

    edit
    /opt/lampp/etc/php.ini

    add the line :
    zend_extension=/opt/lampp/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so
    and restart apache

  13. thanks for tutorial and if not build xdebug.so download pkg devel at sourceforge for version your xampp

  14. [...] Innanzi tutto ho trovato questo un articolo molto interssante: Installing Xdebug on xampp for linux. [...]

  15. Thanks for the tutorial, it was pretty useful although I ended up using a compiled xdebug.so from an external source

  16. Hello,
    when I try to do ./install I have this message error:
    configure: error: xml2-config not found. Please check your libxml2 installation.

  17. Hi,

    I ran into a problem on a 64 Mint installation. The problem was that XAMPP is only 32-bit and the XDebug module was built in 64-bit mode. I “solved” this by running ./configure, after this modifying Makefile and appending “m-32″ to CFLAGS (I don’t know how to pass -m32 to the configure script). After this I also needed to install the GCC multilib package.

    With these modifications it worked fine. Or, at least, phpinfo() reports I have XDebug.

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.

Join 76 other followers

%d bloggers like this: