Install Xdebug and configure it with webgrind

For EasyEngine Users…

You can use ee debug command which automates some part.

Installing Xdebug

1. Install Xdebug for php

sudo apt-get install php5-xdebug

2. Setup xdebug.ini for ubuntu

vim /etc/php5/fpm/conf.d/20-xdebug.ini

Add following lines:


3. Restart php5-fpm

sudo service php5-fpm restart

Install Webgrind

Under webroot for, run following commands:

mv webgrind-master webgrind

Install graphviz and Gprof2Dot

This is needed for graphical presentation of calls.

apt-get install python graphviz

Webgrind config

Open config.php under webgrind folder. You may need to specify location of dot binary.

static $dotExecutable = '/usr/bin/dot';

Using Webgrind

Goto in your browser and you will see webgrind UI there.

But wait, you may not see any output there as cachegrind files may not have created yet.

Trigger Profiling

You may not see anything as we have set xdebug to profile only on trigger. This is good for profiling sites used in production environment as well as on server with multiple sites using same PHP pool.

You can use this browser extension to trigger profiling:

Always Profile

Be warned, that this can eat up GB’s of space on a live server with decent traffic in an hour!

You can change a line like below and it will profile php code always.


Of course, you will need to reload PHP for change to take effect using service php5-fpm reload

Remote Profiling

We have covered remote debugging with Netbeans here: Please note that changes to debug config in NetBeans article, if you decide to use it.

Xdebug site has more remote options.

For more details, check out the Xdebug Documentation.