How to Install PHP 5 in Apache 2.2 for Windows

25 February 2009

PHP PHP is a powerful Open Source web scripting language which widely used by many web application including many famous Open Source Content Management Systems. This article will guide you how to install PHP in computer with Windows operating system.

This article assumes that you already read the preceding articles:

Apache Module

PHP can install and running as a CGI module or an Apache module. Since most hosting providers are using PHP as an Apache module, so this article will focus only for PHP installation as an Apache module.

Installation
  • Create folder named c:\php5 and c:\php5\tmp .
  • Extract the downloaded php-5.x.x-Win32.zip file under c:\php5
PHP.INI Configuration
  • Go to php folder and rename the file php.ini-recommended to php.ini. This is recommended configuration which sets some non standard settings that make PHP more efficient, more secure, and encourage cleaner coding.
  • Open the php.ini with your text editor.

You can choose which extensions you would like to load when PHP starts by modifying your php.ini with the following steps.

  • Change the extension_dir setting to point to the extensions folder.

extension_dir="c:/php5/ext"

  • Enable the extension(s) you want to use by uncomment or deleting the leading semicolon (;) from the extension you want to load.

In this case, I will ask you to load some important extensions which commonly used by many web applications. Uncomment the lines below:

extension=php_curl.dll
extension=php_gd2.dll
extension=php_mbstring.dll
extension=php_mysql.dll
extension=php_mysqli.dll
  • Find the line

;session.save_path = “/tmp”

and change that line to

session.save_path = “c:/php5/tmp”

  • Save the changes.
Apache Configuration

To make PHP available under your apache web server you need to change the apache configuration file in c:\apache2\conf\httpd.conf.

Open the httpd.conf with text editor like Notepad and do the following changes:

  • Add line below to the end of the LoadModule section.

LoadModule php5_module "c:/php5/php5apache2_2.dll"

  • Search the lines
<IfModule mod_dir.c>
DirectoryIndex index.html
</IfModule>

The DircetoryIndex used to tell apache the default file which should open. If you want your web server to open index.php as a first default page then you have to put it on first order.

<IfModule mod_dir.c>
DirectoryIndex index.php index.html
</IfModule>
  • Search the line

TypesConfig conf/mime.types

  • Change that line to
TypesConfig conf/mime.types
AddType application/x-httpd-php .php
  • Go to the last line and add the line:

PHPIniDir “c:/php5”

  • Save the changes.
Testing the Installation
  • Restart your Apache service by using NET STOP APACHE followed by NET START APACHE in the command line. Alternatively you can
    open Settings – Control Panel – Administrative Tools – Services and do restart the Apache service in the list.
  • If the Apache successfully started then your installation of PHP is successful.
  • To make sure your PHP is running and configure properly, you can test it by creating a test file under c:\apache2\htdocs folder.
  • Open your text editor and create these following lines:
    <?php phpinfo(); ?>
  • Save the file name to info.php.
  • Open your browser and type http://localhost:8080/info.php. Your browser should show the version and many other configurations of your php installation.
  • If you cannot see that information then re-check your settings, especially in httpd.conf file.
  • Make sure to restart the Apache service each time you edit the httpd.conf or php.ini.
  • Now when you run the http://localhost:8080/info.php then you should see the gd, mbstring, and mysqli section as your installed extensions.

Note: If somehow you can’t find the mysqli extension, please follow the next section below.

Update MySQL Native Driver
  • This part only necessary if you can’t find mysqli extension when you run http://localhost:8080/info.php
  • Extract the downloaded MySQL Native Driver zip file and overwrite the file php_mysqli.dll which already exist in c:\php5\ext
  • Restart Apache service and run http://localhost:8080/info.php

Next article: How to Install PHPMyAdmin in Apache 2.2 for Windows.


  1. Manuel
    9 October 2008

  2. Danny Gunawan
    9 October 2008

  3. Rob Miller
    24 August 2009