Hamid Nazari's Phalak

How to set up Xdebug on Windows and IIS 7

Xdebug Logo

Xdebug is a cool extension for PHP which allows developers to debug and profile their PHP code. It really comes in handy when you want to debug your code to fix an issue or want to find bottlenecks in your code to make it perform better. I’m making this tutorial so that everyone with any background knowledge could get started with Xdebug.

1. Get latest stable release of Xdebug from this page according to your PHP installation.

Note: If you don’t know the details of your PHP installation, use phpinfo to find out. Architecture and PHP Extension Build are the information that will help us decide. If the architecture is x86 then pick a 32-bit version, otherwise if it’s x64 pick a 64-bit edition. Compiler indicates what kind of compiler has been used to compile this PHP build. It should be either VC6 for older versions of PHP or VC9 for the newer ones. Another thing that you should pay attention to is the Extension Build being NTS or TS which stand for Non Thread Safe and Thread Safe respectively.

phpinfo without xdebug installed

phpinfo without xdebug installed

2. You can skip this step but preferably, put the downloaded DLL inside your PHP extensions directory.

Note: To find out what the address of this directory is, find extension_dir in phpinfo.

3. Open php.ini in a plain text editor (Notepad++ is great for this task) and append these lines at the end of it. Make sure you use absolute addressing and your own downloaded file’s name.

Note: Again, you can find the location of php.ini in phpinfo. It’s attribute name is Loaded Configuration File.

zend_extension = "C:\Program Files\PHP\ext\php_xdebug-2.1.0-5.3-vc9-nts.dll"

4. Restart IIS by opening command prompt and typing in the following command or use Internet Information Services (IIS) Manager.

> iisreset /noforce
Restarting IIS

Restarting IIS

5. Check phpinfo one more time to make sure that Xdebug is installed.

phpinfo with xdebug installed

phpinfo with xdebug installed

Xdebug is now installed and ready to use. Execute this code to see it for yourself how it overwrites var_dump and generated errors by PHP.

Note: html_errors in your php.ini should be On.

$primes = array(2, 3, 5, 7, 11, 13, 17);
function foo()
	bar(5, 7);
function bar($param1, $param2)
	$local1 = 1;
	$local2 = 2;
Xdebug overwrites var_dump and PHP errors

Xdebug overwrites var_dump and PHP errors

And the following is what you would get normally.

Normal var_dump and PHP errors

Normal var_dump and PHP errors

Move along to my next tutorials on debugging and profiling using xdebug too see it more in action. Also check out Xdebug’s documentation to find many many useful stuff in this regard.

Comments (0) Trackbacks (0)

No comments yet.

Leave a comment

No trackbacks yet.