Tuesday 8 March 2016

Steps for installing and configuring XHProf with Drupal 7 on CentOS 7

Execution time of each and every method involved in a single HTTP Request is the key factor for overall page load time and the process of collecting these information is called profiling.The two more popular extensions for this purpose are Derick Rethans‘ Xdebug and Facebook’s XHProf. Here we are focussing on XHProf only. 


Please follow the below steps to setup XHProf for Drupal 7 on your CentOS 7 environment with Apache.

Step 1:
Install plugin
            sudo yum --enablerepo=remi,remi-php55 install xhprof
This plugin is for loading graphical content
            sudo yum --enablerepo=remi,remi-php55 install php5-common graphviz

Step 2:
Enable the Xhprof module within php.ini file and specify the directory.
            extension=xhprof.so
            xhprof.output_dir="/tmp/xhprof"

Step 3:
Checking configuration files
cd /usr/share/xhprof/
Here, two folders xhprof_html and xhprof_lib should be available

Step 4:
Create a sym link to xhprof configuration files
sudo ln -s /usr/share/xhprof/xhprof_html/ xhprof

Step 5:
Virtual host configuration.
Open file --
vi vhosts.conf
Add entry --
<VirtualHost *:80>
        ServerAdmin vagrant@xyz.com
        DocumentRoot /var/www/html/xhprof
        ServerName xhprof.localhost
        Serveralias xhprof.xyz.com
        <Directory "/var/www/html/xhprof">
                #AllowOverride None
                AllowOverride All
                Require all granted
        </Directory>
</VirtualHost>

Open windows host file and add entry --
192.168.56.101 xhprof.xyz.com


Step 6:
Create a temporary directory.
cd /tmp
mkdir xhprof
chmod 777 /tmp/xhprof

Step 7:
Restarting PHP and httpd service.
            sudo systemctl restart php-fpm
            sudo systemctl restart httpd

Step 8: Enable Xhprof with Drupal 7 Devel module.
              drush dl devel
              drush en devel
drush vset devel_xhprof_enabled 1
drush vset devel_xhprof_directory "/usr/share/xhprof/"
drush vset devel_xhprof_url "http://xhprof.xyz.com/"

Step 9:
Clear drush cache and drupal cache
drush cache-clear drush
drush cache-clear all

Note:
Do not keep it (XHProf) enabled all the time. Before hitting the particular URL (for which you want to do profiling) on your browser enable it first. Once the page execution been completed then disable it immediately using below drush command.
To Enable : drush vset devel_xhprof_enabled 1

To Disable : drush vset devel_xhprof_enabled 0


If you feel it useful then please like it and share it, Thanks.

No comments :

Post a Comment