How to Install PHP on IIS
Installing PHP in Windows requires more than just running the PHP installation package. There are additional actions that need to be taken before you can host PHP web pages. Unfortunately, the installer doesnâ€™t do this and you have to set it up manually yourself. You wonâ€™t find any documentation on the PHP site, but the procedure is fairly easy to follow.
The first thing you need to do is get the latest version of PHP for Windows from http://www.php.net/downloads.php. Run the installer and follow the steps until you reach the Web Server Setup form.
Select IIS CGI if you are installing PHP on IIS 5 or earlier (i.e. Windows XP). If you are using IIS 6 or 7 (Windows 2003 or 2008), use the IIS FastCGI option if its installed because it will give PHP better performance on your server.
Click on the drive icon next to PHP and select Entire feature will be installed on local hard drive. This will install all of the libraries and documentation that come with PHP. Its easier installing everything now than finding out later that you need a certain feature. Iâ€™ve also found that install PHP on C:\PHP\ works better than installing on C:\Program Files\PHP\. Iâ€™m not sure why, but there is probably a setting Iâ€™m missing when I install it in the Program Files folder.
Youâ€™ll get this error message at the final step of the installation:
Press OK and then press the Finish button when the next form is displayed.
Now you need to test the PHP installation by creating a virtual folder in IIS with a PHP page in it. Name the virtual folder as test and the web page as index.php.
Place the following code in index.php:
When you browse to this folder, i.e. http://localhost/test/, you will get the following error message:
In order for PHP to work properly, you need to modify the php.ini file, create a subfolder, and make some changes to IIS. This procedure is described in the following steps:
- Create a folder call Temp in the folder where PHP was installed.
- Open the php.ini file in an editor. This settings file is located in folder where PHP was installed.
- Search for upload_tmp_dir and session.save_path in php.ini. Change the locations to point to your Temp folder: C:\PHP\Temp.
- Go into the IIS management console and right click on Default Web Site or the web site that you created to install your PHP web site in. Select Properties and open the Home Directory tab. Press the Configuration button to open the Application Configuration form.
- Press the Add button and enter the following information (see image below):
- Select the Documents tab and press the Add button. Set the Default Document Name to index.php. This is the default document that gets opened when you browse to a folder (i.e. http://localhost/test/).
Test the PHP web site by browsing to it (i.e. http://localhost/test/). You should see the word Test displayed in web browser.