How to Install PHP 5 in Apache 2.2 for Windows
9 October 2008
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:
- How to Install Apache, PHP and MySQL in Windows – Preparation
- How to Install Apache 2.2 in Windows
- How to Install MySQL 5.0 in Apache 2.2 for Windows
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.
- Find the line: ;session.save_path = “/tmp” and change that line to be session.save_path = “c:/php5/tmp”
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:/php5/ext”
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_gd2.dll
extension=php_mbstring.dll
extension=php_mysql.dll
extension=php_mysqli.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:\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 line
TypesConfig conf/mime.types
- Change that line to become:
TypesConfig conf/mime.types
AddType application/x-httpd-php .php
- Search the lines below:
DirectoryIndex index.html
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.
- 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
In the next article I will describe How to Install PHPMyAdmin in Apache 2.2 for Windows.
9 October 2008
I still cant see the info.php test page even after updating the php_mysqli.dll but I do see the “It works” HTML from http://localhost:8080.
9 October 2008
Have you create the info.php file? You have to create this file manually for testing.
I have update this article to includes the mysql extension together with mysqli for compatibilty reasons.