Installing xhprof on RedHat 6

After listening to a great session on PHP profiling at the Pacific Northwest Drupal Summit I decided to install it on a dev machine at work. It runs RHEL6 which is a great system, though sometimes it is a bit of an oddity to work with.

Installation is pretty straight forward, do not expect to be able to use PECL to install the package though as phpize is referenced incorrectly in the PECL package, as far as I could find using Google. However, we can compile it from source without much problem.

First go to the location that you install scripts, I chose /usr/local/bin, then you grab the latest copy of xhprof and start making it happen.

cd /usr/bin/local

wget http://pecl.php.net/get/xhprof-0.9.2.tgz

tar zxf xhprof-0.9.2.tgz

We then navigate into the extension directory of xhprof, run phpize, configure, and then use make to compile the extension.

cd /xhprof-0.9.2/extension

phpize

./configure

make

make install

make test

You should see that you passed all 8/8 tests. Then add xhprof to your php.ini file and restart apache.

You want to add the following to your php.ini file, mine is in /etc/php.ini
vi /etc/php.ini

[xhprof]
extension=xhprof.so
xhprof.output_dir="/var/tmp/xhprof"

You need apache to be able to write to the folder you have just named so go create it and change ownership to apache:root.
cd /var/tmp/

mkdir xhprof

chown apache:root xhprof

Then restart apache. apachectl -k graceful

The final step mentioned, but not shown at the excellent writeup on techportal.ibuildings.com/2009/12/01/profiling-with-xhprof is that you need to symlink the xhprof_html folder so that you can access the reports in a browser. Do this by navigating to your web root, mine is at /var/www/html and create a symlink.ln -s /usr/local/bin/xhprof-0.9.2/xhprof_html xhprof

Enjoy using xhprof with the devel module in Drupal and with your other projects.