Configuring PHP on Windows Systems
Published: January 15th, 2009 by: Kurtis
Though not necessary, running PHP on your home machine can make development much quicker and easier. Without affecting the actual website, you can edit files and execute them locally, uploading all to the server when finished. This article will cover the installation of Apache and configuration of PHP on your local Windows machine.
First of all, let’s detail the major all-in-one installers. The two most popular are XAMPP and WAMP (notice the AMP they have in common). XAMPP is an acronym, each letter standing for a feature of the package:
- X: means the package is cross-platform (Linux, Windows, etc)
- A: Apache HTTP Server
- M: MySQL
- P: PHP
- P: Perl
The XAMPP package, which can be easily downloaded and installed on Windows machines, includes the following features as well: mod_php, mod_perl, mod_ssl, OpenSSL, phpMyAdmin, Webalizer, Mercury Mail Transport System for Win32 and NetWare Systems v3.32, Ming, JpGraph, FileZilla FTP Server, mcrypt, eAccelerator, SQLite, and WEB-DAV + mod_auth_mysql. It may seem like a lot because, well, it is! Take my word for it: if you’re looking for a quick, simply install with all of the necessities, XAMPP is great!
WAMP is also an acronym, where the AMP stands for Apache, MySQL, and PHP, and the W here specifies that it only works on Windows machines. WAMP also includes phpMyAdmin but is much more stripped in its features. I suggest WAMP if you want a lighter install with only the bare-bones features.
The next option is to install Apache and PHP on your own, though this solution is still rather easy. By downloading the Apache installer (choose the last Win32 option) and running through the steps (detailed later), you can couple it with an easy PHP installer, either one available directly from the PHP website, located here, or one from a third-party source, like the EasyWindows Installer. Following the steps they suggest will allow another quick installation option. This is certainly the lightest quick installation available.
The last option is certainly the toughest, but I, as well as the PHP developers themselves, recommend it. Installing PHP yourself allows you to take a close look at the files that configure it and work with them as well. This may seem intimidating to some, so that’s why there are so many other options available. You can follow the manual instructions at php.net or follow my instructions for installing Apache and PHP below. I’ve sifted through PHP’s instructions to create the easiest-to-understand steps I could.
Let’s begin by configuring PHP.
- Download the PHP package. I suggest the latest Windows binary (5.2.8 as of this article).
- Extract the entire package to a folder on your machine (e.g. C:/PHP). Note that the latest releases of PHP do not create their own folder, so you must extract them to the folder you wish for PHP to reside in.
- Make php5ts.dll available to the web server and CGI and CLI binaries through one of the three following options:
- Copy the file to the windows system directory (C:/WINDOWS)
- Copy the file to the web server’s directory
- Add the path to PHP to the PATH environment variable by following these easy steps.
- Set up a valid php.ini file. There are two available in your PHP folder: php.ini-recommended and php.ini-dist. The “recommended” file makes your installation more secure, but if you are installing on a home machine, the “dist” file is fine. Simply save the file as php.ini in your PHP folder.
- Now, edit the php.ini file you just saved by finding the doc_root variable and setting it equal to the following: C:\Apache\htdocs
- Find the extension_dir variable and set it equal to C:\PHP\ext
- Be sure to use backslashes in the php.ini file.
- Save the file and close it.
Now you can begin installing Apache and finishing configuration.
- Download the latest release of Apache here (choose the last Win32 option). Use the installer to set up Apache, and install it in C:/Apache.
- To set up PHP to work as an Apache module, open the httpd.conf file (located in C:/Apache/conf/) and add the following lines to the bottom of the file:
- LoadModule php5_module “c:/php/php5apache2_2.dll”
- AddType application/x-httpd-php .php
- PHPIniDir “C:/PHP”
- Be sure to use forward slashes in the httpd.conf file.
- Save the file and close it.
- Restart Apache by double-clicking the icon in your system tray. Click the “Restart” button, and if Apache restarts, everything is ready to work! If not, try working back through the steps and make sure your settings are correct.
With Apache and PHP installed, visiting http://localhost/ will load the files from your C:/Apache/htdocs folder, usually by default with an HTML file saying It works!
Whatever method you employ, setting up Apache and PHP is rather easy and simple to do. Choose the manner best suited for you, and follow the proper steps. In no time, you’ll have your own Apache server with PHP set up on your computer.