Setup local PHP development environment on Windows
Here I want to show you how I have my local php development environment setup with XAMPP, Xdebug and PHPUnit. With this setup, you will be able to develop and run your PHP applications on your windows localhost, be able to unit test your PHP application and have a code coverage report generated by PHPUnit.
Let's download and install XAMPP first.
This is very straight forward. We just need to download the latest XAMPP zip file from http://www.apachefriends.org/en/xampp-windows.html and extract all contents to "C:\xampp". I use "C:\xampp" to avoid windows permission issues. To verify the XAMPP installation, find and double click on the "C:\xampp</em>xampp-control.exe" file to bring up the control panel, click on the "Start" button next to "Apache" to start the Apache web server. Now, start your browser and go to http://localhost, you should see the XAMPP default welcome page. Your localhost document root is at "C:\xampp\htdocs\".
Next, let's install and configure Xdebug.
Download the latest precompiled Xdebug DLL from http://www.xdebug.org/download.php. Put the DLL inside "C:\xampp\php\ext\".
We need to tell our PHP installation to use Xdebug. There are 2 php.ini files come with XAMPP, "C:\xampp\php\php.ini" and "C:\xampp\apache\bin\php.ini". The file under "C:\xampp\" controls the command line PHP. Obviously the php.ini under "C:\xampp\apache\bin\" controls the Apache PHP module. For some reason, enabling Xdebug for the Apache PHP module will lead to unexpected Apache server crashes. So I only have Xdebug enabled for my command line PHP. 2 reasons for this. One is that I really do not have time to figure out why it's not working for my Apache PHP module. Second is my motivation of installing Xdebug at the first place. I'm using Zend Framework for my PHP project development, I get a comprehensive error stack trace from the framework already. I want to install Xdebug, so that when I run my PHP unit tests, I can let PHPUnit generate a nice looking code coverage report (Xdebug is required for this job).
So ... to configure Xdebug for my command line PHP, I need to modify "C:\xampp\php\php.ini". In the ini file, find sections for "[Zend]", comment out all lines under it. Find section "[XDebug]", comment out all lines, and put in this
[XDebug]
xdebug.remote_enable=1
xdebug.remote_host="localhost"
xdebug.remote_port=9000
xdebug.remote_handler="dbgp"
zend_extension_ts="C:\xampp\php\ext\php_xdebug-2.0.5-5.2.dll"
Okay. we now can move onto PHPUnit
We can download and install PHPUnit with XAMPP's pear support. Open windows command prompt as administrator and do the following
cd c:\xampp\php
go-pear.bat
PEAR_ENV.reg
pear channel-discover pear.phpunit.de
pear install phpunit/PHPUnit
We should now have PHPUnit download and configured at "C:\xampp\php\PEAR\PHPUnit\".
Conclusion
We now have a working local copy of PHP, MySQL, Xdebug and PHPUnit. With this setup, we are ready to develop and test our applications on the localhost.