Install a WAMP (Windows, Apache, MySQL, PHP) environment in 4 easy steps, one of which is optional and one of which isn’t really a step at all! ;)
These days I’ve been working on Linux servers for a long time, so when I had to install all the things necessary for PHP development on Windows, I realized it isn’t necessarily a simple task… but it can be for you, as I’ve compiled everything you need to know/do to get up and running to this post.
Step 1: Download
The first step is to go to the XAMPP homepage and grab the files. I recommend getting the Installer, because it automates some tasks you’d otherwise have to do by hand.
Step 2: Install & Configure
Run the installer, wait for it to finish and you’re done with the installation. Next, we need to modify Apache’s configuration a bit to enable mod_rewrite, which for some weird reason isn’t enabled by default.
Go to xampp_install_dir\apache\conf and open httpd.conf. Find the line which says:
#LoadModule rewrite_module modules/mod_rewrite.so
then remove the # from the start. Save and close.
Step 3: Fine tune
The things done in this chapter are optional, but can be very convenient.
Go to xampp\apache\bin and open php.ini
Turn on all errors
Since this will be a development server, let’s change error reporting to E_ALL. This way we will get more information on things which go wrong in our code without having to change the error reporting manually. Look for..
error_reporting = E_ALL & ~E_NOTICE
and change it to
error_reporting = E_ALL
Disable magic quotes
Magic quotes are one of the “features” of PHP that usually cause nothing but problems. What are they? Basically, it means PHP will automagically escape quotes in get, post and cookie parameters, often causing issues with backslashes appearing all out of nowhere etc. – Originally intended as a security feature, but it is not much of help, and it’s also being removed with PHP 6, so let’s disable it on our development server as well:
Find “magic_quotes_gpc = On” and change it to “magic_quotes_gpc = Off”
Put the downloaded DLL file to xampp\php\ext and rename it to php_xdebug.dll
Then, find this in the php.ini:
[Zend] zend_extension_ts = "x:\path\to\xampp\php\zendOptimizer\lib\ZendExtensionManager.dll" zend_extension_manager.optimizer_ts = "x:\path\to\xampp\php\zendOptimizer\lib\Optimizer" zend_optimizer.enable_loader = 0 zend_optimizer.optimization_level=15 ;zend_optimizer.license_path = ; Local Variables: ; tab-width: 4 ; End:
Comment out each line with a ;, so that the lines look like this:
[Zend] ;zend_extension_ts = "x:\path\to\xampp\php\zendOptimizer\lib\ZendExtensionManager.dll" ;zend_extension_manager.optimizer_ts = "x:\path\to\xampp\php\zendOptimizer\lib\Optimizer" ;zend_optimizer.enable_loader = 0 ;zend_optimizer.optimization_level=15 ;zend_optimizer.license_path = ; Local Variables: ; tab-width: 4 ; End:
Under the above lines should be the following:
[XDebug] ;; Only Zend OR (!) XDebug ;zend_extension_ts="x:\path\to\xampp\php\ext\php_xdebug.dll" ;xdebug.remote_enable=true ;xdebug.remote_host=127.0.0.1 ;xdebug.remote_port=9000 ;xdebug.remote_handler=dbgp ;xdebug.profiler_enable=1 ;xdebug.profiler_output_dir="x:\path\to\xampp\tmp"
Uncomment the above lines by removing the ;’s from the lines. After restarting Apache, you should have the Xdebug library loaded and working.
Alternative: install Zend Studio debugger
If you use Zend Studio / Zend Studio for Eclipse, and want to be able to debug PHP files with the built-in debugger, you must install the free Zend debugger extension.
You can download the extension from here. Look for a file called ZendDebugger-x.x.x-cygwin_nt-i386.zip, it is the version you want for Windows Apache.
The extension comes with a readme file which explains the installation procedure.
Create a common library directory
The next thing is to create a common library dir. This is something that’s useful if we use the same library (say, Zend Framework) in more than one project, as we won’t have to always copy the library’s code around.
Let’s create a directory for our library files under xampp\php. Create a directory called “library”, then look for “include_path” in php.ini
It probably looks like this:
include_path = “.;x:\path\to\xampp\php\pear\”
Let’s modify it so that it contains our library path:
include_path = “.;x:\path\to\xampp\php\pear\:x:\path\to\xampp\php\library\”
Now we can put our library code to xampp\php\library, and we can use require_once etc. without having to copy the files or redefine the include path.
Step 4: Enjoy!
How to set up PHP CLI (command line interface) on Windows?