Installation of Apache2.2.19 and PHP5.3.6 for Windows web server

PHP has been still common as a server-side scripting language, and, used with Apache, provides an irreplaceable advantage that allows you to build a practical website quickly. This article introduces to you how to install Apache2.2.19 and PHP5.3.6, the latest versions as of June 15. 2011, on a Windows OS.

Download components

First, let’s download the latest version of Apache and PHP. Refer to the following links for download.

You should download a thread-safe version of PHP to work with Apache. Install Apache first and then PHP because you need to customize your setting for Apache as you go through the PHP installation wizard.

Install Apache

Launch the Apache installer.

Apacheのインストール開始画面

The start window of the Apache installation

After accepting the license agreement, you will go on to the window to specify the network domain, server name, and administrator’s email address. If you publicize your server, be sure to enter the names correctly. You can rename later by editing “httpd.conf”.

ホスト&ドメイン&管理者メールアドレス設定画面

Specify the network domain, server name, and administrator's email address.

You will be prompted to specify the setup type next, but the typical installation method will be fine unless you want to specify the installation components. Then, you will be asked to specify the directory where you want to install Apache. The default location is a folder created automatically under Program Files, which is a safe choice for security purposes. Yet, in this case, you will need to consider authorization issues when rewriting a  setting file such as “httpd.conf”. If you build a test website without much care about security issues and change a setting file frequently, you might want to change the installation directory, e.g.,”C:\Apache”.

Apacheのインストール先指定

Specify the location where you want to install Apache

Now you are ready to install. After installation, you will see an icon added to the task tray. Double-click it and the window titled “Apache Service Monitor” appears, where you can manage the state of installed Apache services: start, stop, and restart.

Apacheのサービスモニタ

Apache Service Monitor

Install PHP

Install PHP components next.

PHPのインストール開始画面

PHP installation wizard

After reading the license agreement, you are to specify the installation directory. Similar to the Apache installation, it may be a good idea to change the directory, e.g.,”C:\PHP”.

PHPのインストール場所指定

Specify the PHP installation directory.

You will move on to Web server Setup window. Select “Apache2.2.x Module” and specify your Apache installation location in the next page.

Webサーバセットアップ画面

Web server setup window

Like the Apache installation, basically, the default installation should be fine. In the next page, click “Install” to start installation.

Configure “httpd.conf” file

Go to your Apache installation location, open the “conf” folder, and find the setting file “httpd.conf”, which comes with the backup file whose name ends with “.bak” extension. The following statement is automatically added to the last line of the file, specifying the directory of the PHP components and the module for Apache.

#BEGIN PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL
PHPIniDir "C:\PHP\"
LoadModule php5_module "C:\PHP\php5apache2_2.dll"
#END PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL

This is not enough; you need to add the following statement between <IfModule mime_module> and </IfModule> in order to get a “.php” file recognized as PHP script.

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Add “index.php” to the item “DirectoryIndex” so that it can be used as an index when the client only specifies a directory name.

DirectoryIndex index.html index.php

After the above configuration is completed, restart for the changes to take effect.

Testing

If you have taken the right step, you are supposed to be able to handle PHP files as web script now. Create a file “index.php” in the “htdoc” folder directly under your Apache installation location. Add the following script and display the test page.

<?php phpinfo(); ?>

If your installation has been completed successfully, you can see such a table as below.

設定に成功した場合、PHPのバージョン&コンパイル情報が表示される

After setting successfully, a table above shows the PHP version and compiling information.

This post is also available in other languages.