Popular Posts
Tools and Tips
Search
Tuesday, January 8. 2008
How to install Xdebug for PHP5 on Ubuntu 7.10
This guide will cover how to install Xdebug for PHP5 on Ubuntu 7.10. Xdebug is not only an excellent debugger for PHP, it also has one of my favorite tools for optimizing PHP - A profiler.This profiler will break down your code and determine where your bottlenecks, or slow downs are to ease optimization. Combined with a program to handle cachegrind files, you can benchmark and optimize your scripts quickly and effectively.
We assume you already have Apache and PHP5 working on this system. We will be installing the latest version of Xdebug via PECL (PHP Extension Community Library.) Let's get right into it.
Open up a terminal window (Applications->Accessories->Terminal)
Once that is completed, we can go ahead and install Xdebug
That will go ahead and install Xdebug, and tell you a few things that we'll need in the next step.

You can see that it gives you the location of xdebug.so, which we'll need to add to our php.ini file. Copy the path that it gives you for this module, and open up our php.ini file to edit with:
Your path may be different, depending on how you've installed apache and php5. Now, we're going to add the following line into our php.ini file, using the location of xdebug.so which was given to us earlier. In my case, it will be:
Once you've done this, if you would like to use the profiler, we'll add a single line to turn on profiling in Xdebug.
Now go ahead and save the changes to your php.ini, and restart apache. To make sure that it is working correctly, we can run phpinfo(); in a PHP script and check the copyright information. You should see something akin to the following:

If you do, we're ready to check out the profiler. Now, it's important to understand a few things before getting started with the profiler:
With large scripts, the profile outputs can be huge, so be aware of when you have the profiler on or off.
You will need to use another program, such as KCacheGrind to read the output from Xdebug's profiler (cachegrind files,) which you can install by using:
Now, by default Xdebug will put your cachegrind files into /tmp. It will also name them 'cachegrind.out.*'. You can change these by adding the following into your php.ini
There are also specifiers to use crc, pid, random number, timestamp and so on. You can find all of these here. Should you change any of these, simply restart apache and browse to any page(s) you wish to view the profiler for.
And as a test, I've run a default install of my blog software (serendipity) and opened up the output.

Whalah! You're finished. In the next segment, we'll get down and dirty with the actual optimization itself. If you'd like to learn more about Xdebug, you can check out their website, and documentation.
Save This Page
Stumble It!
Digg it
Installing Xdebug
Open up a terminal window (Applications->Accessories->Terminal)
sudo apt-get install php5-dev php-pear
Once that is completed, we can go ahead and install Xdebug
sudo pecl install xdebug
That will go ahead and install Xdebug, and tell you a few things that we'll need in the next step.

Configuring Xdebug
You can see that it gives you the location of xdebug.so, which we'll need to add to our php.ini file. Copy the path that it gives you for this module, and open up our php.ini file to edit with:
sudo gedit /etc/php5/apache2/php.ini
Your path may be different, depending on how you've installed apache and php5. Now, we're going to add the following line into our php.ini file, using the location of xdebug.so which was given to us earlier. In my case, it will be:
zend_extension="/usr/lib/php5/20060613+lfs/xdebug.so"
Once you've done this, if you would like to use the profiler, we'll add a single line to turn on profiling in Xdebug.
xdebug.profiler_enable=1
Testing Xdebug
Now go ahead and save the changes to your php.ini, and restart apache. To make sure that it is working correctly, we can run phpinfo(); in a PHP script and check the copyright information. You should see something akin to the following:

Setting up the profiler (optional)
If you do, we're ready to check out the profiler. Now, it's important to understand a few things before getting started with the profiler:
With large scripts, the profile outputs can be huge, so be aware of when you have the profiler on or off.
You will need to use another program, such as KCacheGrind to read the output from Xdebug's profiler (cachegrind files,) which you can install by using:
sudo apt-get install kcachegrind graphviz
Now, by default Xdebug will put your cachegrind files into /tmp. It will also name them 'cachegrind.out.*'. You can change these by adding the following into your php.ini
xdebug.profiler_output_dir="/dir/here"
xdebug.profiler_output_name="f.name.here"
There are also specifiers to use crc, pid, random number, timestamp and so on. You can find all of these here. Should you change any of these, simply restart apache and browse to any page(s) you wish to view the profiler for.
Profiler demo
And as a test, I've run a default install of my blog software (serendipity) and opened up the output.

Whalah! You're finished. In the next segment, we'll get down and dirty with the actual optimization itself. If you'd like to learn more about Xdebug, you can check out their website, and documentation.
Share
Save This Page
Stumble It!Digg it
Trackbacks
Trackback specific URI for this entry
No Trackbacks

