Installing Apache and PHP
Installing Apache on Windows
We will start first by installing Apache. Once you have downloaded the apache_2.X.X-win32-x86-no_ssl.msi file, double-click it to start the installer. (Note: the X’s in the file name represent the different versions of Apache, for example: apache_2.2.8.) The installation process is straight-forward and typical for Windows.

Following through the on-screen instructions, you will be prompted for Network Domain, Server Name, and Administrator’s Email Address. For development and testing purposes you can enter localhost for both Network Domain and Server Name and enter anything for the email address, note you can always change these settings later in Apache’s configuration file. You can choose to install Apache as a Windows Service (Apache will start and run automatically with the operating system) or manually for the current user.
Next, select the Typical install option for the Setup Type. On the following screen you can select the default installation directory at C:\Program Files\Apache Group\ or choose any other directory you like. Consider changing it to C:\Apache\, as this is the directory we’ll use through out the tutorial. Click next and then click the Install button to start the installation. After the installation is complete, Apache will be started automatically. To see if everything was successful, fire up your favorite web browser and point it to http://localhost or http://127.0.0.1, you should see a default page similar to the one below.
If you are having installation troubles, scroll down to the bottom of the page for common installation pitfalls and solutions.

Installing and Configuring PHP
We will install PHP manually instead of using the Windows installer, as this is the recommended method, giving you a better insight into the installation and configuration process. Start by downloading the php-5.X.X-Win32.zip file from Php.net, and extract the contents of this file to C:\Php.
In the main PHP directory, you can see various .DLL (Dynamic Link Library) files, which are essentially application extensions used to add further functionality to a program. Since we are installing PHP as an Apache server module, we will need to make sure the php5ts.dll file is available both to PHP and the web server. The easiest and recommend method to accomplish this, is to add the PHP directory to the Window’s PATH environment variable. On Windows XP:
- Goto: Start » Control Panel » System, and select the Advanced tab and click the Environment Variables button.
- Find the
Pathentry in the System variables section and double-click it. - Enter the path to your PHP installation directory (
C:\Php) at the end of the Variable value field, adding a;before the path name. - Hit Ok and restart your computer.
Next we will need to setup a PHP configuration file. In the main PHP directory you’ll see two configuration files called php.ini-dist and php.ini-recommended. Rename the php.ini-dist file to php.ini and save it to C:\Php, this file contains many configurable settings that control PHP’s behavior and is loaded every time PHP is started. The other configuration file php.ini-recommended has been optimized for performance and security and can be used instead of php.ini-dist, depending on your preference. You can edit the php.ini configuration file and modify the settings, don’t worry if you don’t quite understand all the directives, the default settings will be sufficient for testing purposes.
Finally, to add PHP to Apache we need to modify Apache’s configuration file (httpd.conf). Navigate to the conf subfolder in Apache’s installation directory (C:\Apache\conf) and open httpd.conf with a text editor like Notepad. In the configuration file scroll down until you reach a block of LoadModule directives and enter the following lines right after the block:
LoadModule php5_module c:/php/php5apache2_2.dll Addtype appilcation/x-httpd-php .php PHPIniDir "C:/Php"
Save the file and restart the server for the changes to take effect. Now to ensure that PHP is properly working, we’ll create a PHP script. Open your favorite text editor and enter the following line and save it as test.php within Apache’s document root (C:\Apache\htdocs).
<?php phpinfo(); ?>

Launch your web browser and point it to http://localhost/test.php, if you see a page similar to the one above, then PHP was installed successfully!
Installation Troubleshooting
You might have encountered a couple of errors or you are experiencing some installation troubles. No need to worry, below are some solutions and suggestions to common installation pitfalls, to help you get back on track.
- Apache logs all errors it encounters, in a log file called
error.log, its default location is in thelogssubfolder of Apache’s installation directory (C:\Apache\logs\). The error log file lists diagnostic information related to the error and is the fisrt thing you should check if you’re having problems. - By default, Apache listens for requests on Port 80 and will not share that port with other programs bound to it, for example other HTTP web servers and certain firewall programs. You’ll need to close those programs or configure you’re firewall to allow access to Apache.
- If you changed the default port number Apache listens to or if you selected to start Apache manually instead of a Windows Service, during the installation process, you’ll need to append that port number to the end of the URL. (eg.
http://localhost:8080) - When editing the configurations files, always review your changes and make sure you didn’t accidentally insert a typo or extra character into the files.
- Notepad appends a
.txtextension to files by default, when saving your files with a different extension (i.e..php .html) make certain you place the filename in quotes ("test.php"), when entering the filename in the Save As dialog box.
Now that you have a functional web server with PHP installed, we can start to explore the basics and dive further into the nuts and bolts of the language. Along the way, we’ll also examine several different configuration directives in the php.ini file and make additional adjustments to tweak PHP’s performance.
