Install XDebug and WebGrind on CentOS for debugging and profiling

webgrindXdebug is a PHP extension created by Derick Rethans, one of the PHP core developers. Webgrind is an Xdebug profiling web frontend in PHP5. It implements a subset of the features of kcachegrind and installs in seconds and works on all platforms. For quick’n’dirty optimizations it does the job. This article will show how to install XDebug and WebGrind into your development environment for development work.

  1. Install XDebug

    yum install php-pear
    yum install php-devel
    pecl install xdebug
  2. Add XDebug to PHP

    vi /etc/php.d/xdebug.ini
    ### Add the following lines ###
  3. Restart apache.

  4. To test it, create a testxdebug.php file with the following content

    function test()
        echo "Called @ ".xdebug_call_file().":".xdebug_call_line()." from".xdebug_call_function() . PHP_EOL;

    , and run php -e testxdebug.php

  5. Install WebGrind

    mv master
    ### change config file ####
    vi webgrind-master/config.php
  6. Done, run webgrind from your browser to check debugging/profiling information
  7. We can also install KCacheGrind to view debug information on Linux desktop.

Some Notes

  • By default, XDebug does not enable profiling, we must enable it explicitly as in the above configuration
  • If just running XDebug for some specific URL/file, we can use configuration
    xdebug.profiler_enable_trigger = 1

     on .ini file, and then we can enable profiling with GET/POST parameter XDEBUG_PROFILE, e.g. http://localhost/samplepage.php?XDEBUG_PROFILE:

  • If we need to display graph with WebGrind, we must have graphviz installed:
    yum install graphviz*

    , and then, change the configuration file

About NhocConan

A super lazy guy who tries to write tech blog entries in English.He is lazy, so he can only write when he is in a good mood or when he is tired of coding.

Leave a comment

Your email address will not be published. Required fields are marked *