22

PHP XDebug & Webgrind Installation

The Problem

How to get Webgrind which is an excellent profiling frontend and Xdebug up and running on your Apache Webserver with PHP.

The Solution

You can skip the steps below if you already have Apache and PHP installed. For sake of completeness-

We make use of Apache 2.2.x although the following steps should work for Apache 2.0.x also. First download and install the latest version of Apache (apache_2.2.11-win32-x86-openssl-0.9.8i.msi). Then download and install the latest version of PHP (5.2.9 zip package).

Once you have completed installing both, I suggest you set your htdocs to c:\htdocs (if Windows). For this, edit your httpd.conf file in the conf folder and add the following:

DocumentRoot "c:/htdocs"



    Options Indexes FollowSymLinks +ExecCGI
    AllowOverride All 
    Order allow,deny
    Allow from all


Once that is done, restart your Apache Webserver and create a file called phpinfo.php with the following contents:


Point your browser to http://localhost/phpinfo.php and note down whether Thread Safety is enabled or disabled. If you see an output then congrats!. We now have Apache & PHP running.

Xdebug Installation

To install Xdebug, depending on your whether Thread Safety is enabled or disabled download the appropriate version. In my case we get php_xdebug-2.0.4-5.2.8.dll file. Copy the file to your php/ext folder (c:/program files/php/ext) and add the following to your php.ini file (c:/program files/php/php.ini)

zend_extension_ts="c:\program files\php\ext\php_xdebug-2.0.4-5.2.8.dll"

[xdebug]
xdebug.profiler_enable = 1
xdebug.profiler_output_dir = "c:\htdocs\webgrind\tmp"
xdebug.profiler_output_name = cachegrind.out.%t.%p

Now restart your webserver and point your browser once again to phpinfo.php and if all went well then you should see the following:

Php Info Output

Notice the Xdebug v2.0.4, Copyright (c) 2002-2008, by Derick Rethans in the output. Now lets move on to Webgrind Installation.

Webgrind Installation

First download and extract the latest version of webgrind (webgrind-release-1.0.zip) to your c:/htdocs directory. Create a new folder called tmp in the webgrind folder (c:\htdocs\webgrind\tmp). Edit the config.php file in the webgrind folder and edit the storageDir and profilerDir to:

static $storageDir = 'c:\htdocs\webgrind\tmp';
static $profilerDir = 'c:\htdocs\webgrind\tmp';

Once that is done, add a .htaccess in the webgrind folder with the following contents

php_flag xdebug.profiler_enable 0

The above code is to ensure that Xdebug does not profile Webgrind itself.

Now point your browser to http://localhost/phpinfo.php so that we can profile something. The goto http://localhost/webgrind and view your profiled script!

Webgrind

Notes

If Webgrind takes too long to load, you should occasionaly delete the files from the tmp folder (c:/htdocs/webgrind/tmp)


447 Words
33210 Views