Setting Up Your Own Web Server on a Windows Machine – Part II (PHP)

This tutorial will show you how to install and configure PHP under Windows XP. This tutorial requires you to have Apache HTTP server installed on your local machine. If you haven't done so, you can complete part one of this tutorial. We will use Apache version 2.2.4 and PHP 5.2.1 for this tutorial.

Downloading PHP

Same as Apache, we will use the latest version of PHP. As the time of writing, the latest version is 5.2.1. Download PHP 5.2.1 here.

You can also download a copy from PHP's official site. Just go to http://us3.php.net/downloads.php, and follow the link PHP 5.2.1 zip package, select a mirror which is closest to you. Note that we are using the zip version, not the one come with a installer.

Once you have downloaded the zip package, extract it to anywhere you want. The suggested location is C:\php.


Installing PHP as an Apache Module

It is time to configure Apache so it can serve PHP pages. We will configure PHP as an Apache module.

Open Apache's configuration file, [PATH_TO_APACHE]/conf/httpd.conf in a text editor. If you installed Apache to the default location, it can be found at C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf.

Add the following lines to the end of Apache's configuration file:
Important: Due to a bug in PHP, you have to provide different DLL file depending on the version of your Apache. Make sure you are adding the correct DLL file for your version of Apache!

For Apache 2.2.4

For Apache 2.0

That's it, you've just enabled PHP support on Apache.


Testing PHP Installation

To verify PHP is installed properly, create a php file under your Apache's document root, save it as info.php. By default, Apache's document root is located at [PATH_TO_APACHE]\htdocs.

Insert the following PHP code into info.php:

Visit http://localhost/info.php. If your PHP installation is working properly, you should see a page generated by phpinfo():

phpinfo.gif


Configuring PHP

Similar to Apache, you can configure PHP by changing its configuration file. Navigate to the root of your PHP installation directory, you will find a file named php.ini-recommended. Make a copy of this file and rename it to php.ini. Open php.ini in a text editor.

Again, you will see a lot of options provided for you to fine-tune PHP. However, there are only a few configurations you may want to modify at this time.

Note: Texts after ";" are comments.

Setting Error Reporting Level

Since we are setting up a test server, we want to see error messages generated by the PHP scripts during the execution time - it makes debug much easier.

If you want to see execution error messages in your browser, make sure you set error_reporting to E_ALL and display_errors to On:

Turn display_startup_errors on is recommended because it enable you to track down startup errors easily.


Setting Extension Path

Make sure you set extension_dir to the correct path before you enable any extensions.


Enabling/Disabling an Extension

Remove the comma ";" in front of an extension to enable it; add a comma to the front to disable it.

Some extensions require extra libraries (DLL files under the PHP root directory) to run, for instance, extension php_mysql.dll requires libmysql.dll to run. Make sure those extra libraries are visible by Apache. Here are two ways to make Apache to recognize them:

  1. Add PHP's root directory to your system path
  2. Copy the required DLL files to Apache's bin folder

You can choose either way. Don't forget to restart your computer if you have used the first method.

Here's a list of extensions in the default php.ini:

Next: Installing MySQL

2 Comments Setting Up Your Own Web Server on a Windows Machine – Part II (PHP)

  1. Miro Vasilj

    Hi,
    I am running Vista (Home Premium) on HP Pavilion (Core 2Duo E63000).
    I have Apache2.2 working successfully (Apache Monitor confirms it).

    I have done all configuration in php.ini, apache/../httpd.conf, windows/hosts etc.

    When testing 'hello.html' in Flock browser under http://localhost:8080/hello.html
    It would work and display
    HELLO
    So, that means that the Browser can work fine with the regular '.html' files.

    But I have a problem with http://localhost:8080/
    and
    http://localhost:8080/index.php

    Where 'index.php' is my PHP file with phpinfo(),
    and the browser goes WHITE BLANK (that is showing nothing).

    My server root directory is 'C:/htdocs', and here are the files index.php and hello.html.

    Please advise any suggestions or comments that you might have.
    Regards,
    MV

  2. Alex S

    I would just like to say thank you for such a clear, concise, straight-forward guide to a DIY WAMP set-up!

    I've had to set these up quite a few times now, and every time I hop over to this guide to jog the memory!

Comments are closed.