Installing Apache PHP and MySQL on windows

The goal of this article is to setup a development environment for PHP based web application development on a windows box.

This involves the following steps

  1. Installing Apache Web Server

  2. Installing PHP Engine
  3. Configuring Apache to Run PHP

  4. Installing MySQL Database Server

  5. Installing PhpMyAdmin for managing the database server

1. Installing Apache Web Server

First let us install, configure and run Apache 2.0 under Microsoft Windows.(Windows NT, Windows 2000, Windows XP and Windows .Net Server 2003)

There are two options for installing apache

  1. Use the latest binary distribution
  2. Compile apache from source

Here we will see how we can install Apache using the binary distribution. For this first download the latest version from http://httpd.apache.org/download.cgi. On the page - under the "best available version" click "Other files" for getting the win32 distribution. From the binaries folder download the latest version file with .msi extension. You need Microsoft Installer 1.2 or above for the installation to work. To start installation run the installer.

The installer will take you through the configuration process, where you have to provide your server details. After installing Apache, you can edit the configuration files in the conf subdirectory as required.

Now you can run apache by

  • Selecting "Start" in "Apache Http Server" group from your Star Menu.
  • Run as command line application:
    From bin folder of apache installation you can controll apache using the following commands:
    apache -k start
    apache -k stop
    apache -k shutdown
    apache -k restart
  • Running Apache as a service:
    For running apache as a service execute the following command from bin folder of apache installation:

    apache -k install

    you can uninstall the service by executing:
    apache -k uninstall

    Once the service is installed the apache can be started and stopped with the net commands.

    net start Apache2
    net stop Apache2

Now you can test the installation by launching a browser and entering

http://localhost/ or http://127.0.0.1/

If you have configured apache to run from a different port than port 80 then it has to be explicitly specified in the url like http://localhost:8080/ or http://127.0.0.1:8080/

For a detailed explanation on how to install and configure Apache. You select the version of apache from the documentation section in http://httpd.apache.org/download.cgi.

2. Installing PHP Engine

Now let us manually install and configure PHP with Apache on Microsoft Windows.Now let us manually install and configure PHP with Apache on Microsoft Windows. For this first download the binary distribution of PHP from http://www.php.net/downloads.php.

Extract the distribution file into a directory of your choice. C:\php will ideal.If you are installing PHP 4.x insted of 5.x, you should move all files located in the dll and sapi folders to the main folder.

Now to make php4ts.dll / php5ts.dll available, add C:\php to the Environment Variable PATH. You have to restart the computer before proceeding further.

Next step is to create a valid configuration file for PHP,"php.ini". Recommended way is to rename the file named "php.ini-recommended " to "php.ini". This file has to be moves to a location where PHP is able to find. Windows directory (C:\windows or C:\winnt) is one of the many choices.

PHP is now setup on your system!

Now lets see how to configure Apache to run PHP.

3. Configuring Apache to run PHP

There are two ways to set up PHP to work with Apache 2.0.x on Windows.

  • Use the CGI binary
  • Use the Apache module DLL.

In either case you need to edit your httpd.conf to configure Apache to work with PHP and then restart the server.

By using the CGI setup, your server is open to several possible attacks. So its ideal to install PHP as Apache Module.

#For PHP 4 do something like this:

LoadModule php4_module "c:/php/php4apache2.dll"
AddType application/x-httpd-php .php

# For PHP 5 do something like this:
LoadModule php5_module "c:/php/php5apache2.dll"
AddType application/x-httpd-php .php

# configure the path to php.ini
PHPIniDir "C:/php

4. Installing MySQL Database Server