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 ###
    zend_extension=/usr/lib64/php/modules/xdebug.so
    
    xdebug.default_enable=1
    xdebug.scream=1
    xdebug.profiler_enable=1
    xdebug.profiler_output_dir=/home/tmp/xdebug
  3. Restart apache.

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

    <?php
    function test()
    {
        echo "Called @ ".xdebug_call_file().":".xdebug_call_line()." from".xdebug_call_function() . PHP_EOL;
    }
    
    test();
    ?>

    , and run php -e testxdebug.php

  5. Install WebGrind

    wget https://github.com/jokkedk/webgrind/archive/master.zip
    mv master master.zip
    unzip master.zip
    ### 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
    xdebug.profiler_enable=0

     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

Leave a comment

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