How to Install PHP in Apache for Windows

12 April 2007

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

Extract the downloaded php-4.4.x-Win32.zip file under c:\apache\ folder for easier later maintenance.

Rename the extracted folder c:\apache\php-4.4.x-Win32 to c:\apache\php.

Note: You can actually place the installation or rename the PHP folder with anything you want as long as there is no space in the folder name.

Copy all files in c:\apache\php\sapi\ to c:\apache\php\.
Copy all files in c:\apache\php\dlls\ to c:\apache\php\.

Windows Environment
  • Open Settings – Control Panel – System and click the Environment Variables under Advanced tab.
  • In the System variables, edit the Path variable and put ;c:\apache\php at the end of Variable Value.
  • Click OK to save the changes in any appeared window dialogs.
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.
Find the _magic_quotes_gpc_ and set it to On.
  • Find the session_save_path and uncomment that line. This is done by deleting the leading ; from that line.
Extensions

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 directory where your extensions live. Please do not forget the last backslash. For example:

extension_dir=“c:/apache/php/extensions/”

* Enable the extension(s) you want to use by uncomment or deleting the leading ; 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_mbstring.dll
extension=php_gd2.dll

  • Save the changes.
Apache Configuration

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

Be aware, when adding path values in the Apache configuration files on Windows, all backslashes such as c:\foldername\file.ext must be converted to forward slashes, as c:/foldername/file.ext.

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

  • Add to the end of the LoadModule section.

LoadModule php4_module “c:/apache/php/php4apache.dll”

  • Add to the end of the AddModule section.

AddModule mod_php4.c

  • Search the line:

  • Add this line below

AddType application/x-httpd-php .php

  • Search the lines below:

DirectoryIndex index.html index.htm

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.

DirectoryIndex index.php index.html index.htm

  • Save the changes.
  • Restart your computer to make the sure the environment variables changes applied.
  • Check your Apache service from Settings – Control Panel – Administrative Tools – Services.
  • If the Apache successfully started then your installation of PHP is successful.
Testing and Reconfigure
  • To make sure your PHP is running and configure properly, you can test it by creating a test file under c:\apache\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/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.
  • Now take a look at the value of Configuration File (php.ini) Path showed. If the path shown is different than your original php.ini path then you should copy your php.ini into the folder shown.
  • 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.
  • Now when you run the info.php then you will find the gd and mbstring section as your installed extensions.

In the next article I will describe How to Install MySQL in Apache for Windows.