Steps to Install xhprof in ubuntu and integrate xhprof with yii 2 framework

First we have to install xhprof in ubuntu ( integration )

Install graphviz 

sudo apt-get install graphviz
sudo apt-get install libgv-php5

This step is to generate callgraph of xhprof


Install Xhprof by pecl

sudo pecl install xhprof-0.9.4

 Add and enable php module XHProf to PHP5:

sudo -s
echo "" > /etc/php5/mods-available/xhprof.ini
php5enmod xhprof

Test it

php -i|grep xhprof

xhprof => 0.9.4

Install XHProf report UI:

cd /var/www/html
git clone

Create a test script in index.php: 

// Your code here
$XHPROF_ROOT = "/var/www/html/xhprof/";
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";
$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, "foobar");

Navigate to 


If you want use it with your all core php projects then please use it like this

Create header.php, and footer.php and change apache2 configuration so that you can track your request automatically

php_value auto_prepend_file /var/www/html/xhprof/header.php
php_value auto_append_file /var/www/html/xhprof/footer.php

Done installing xhprof and viewed report  for core php  now let integrate to yii 2 framework

Integrating with Yii 2

Navigate yii 2 project root path

make sure you installed using composer or install composer

composer require stevad/yii2-xhprof
composer update

Check vendor folder you will have 


if it exist you have successfully installed the plugin 

Now add these lines to config/main.php

'bootstrap' => [

'components' => [
        'xhprof' => [
            'class' => 'stevad\yii2xhprof\XHProfComponent',
            'libPath' => '/var/www/html/xhprof/xhprof_lib', // (from git clone)
            'htmlReportBaseUrl' => 'http://localhost/xhprof/xhprof_html',  //(from git clone)

Thats it You are done

Go back to yii project in browser.