Installing PHP 5 on IIS in 5 simple steps


2. Set Your Environment Variables

For this step we'll need to use the Windows GUI, so rather than just write out all the steps I'll use images to do most of the talking.

  • Right click on the My Computer icon and select the properties menu item. You should be presented with a window as shown below in figure 1. Select the Advanced tab and then click the Environment Variables button at the bottom.

Figure 1

  • Scroll through the System variables list at the bottom until you come to the path variable. Select it and then click the edit button as shown below in figure 2.

figure 2

  • Move to the end of the text in the Variable value field and type in the path to the PHP directory you created earlier in step 1 (e.g. D:\PHP). Make sure that there is a semi colon (;) separating the new value you're entering and the previous one, and also place another semi colon (;) after as shown below in figure 3. Once you have added the path click on the ok button to save it and return to the previous window.

figure 3

  • This time we need to create a new environment variable. From the Environment Variables window click on the New button towards the bottom as shown below in figure 4.

figure 4

  • You should now see the New System Variable window as shown below in figure 5. In the Variable name field type in PHPRC, and in the Variable value field type in the path to your PHP install directory (e.g D:\PHP) as shown below. Once done click the ok button to create and save the variable. This PHPRC variable tells Windows where to look for your php.ini file, and if it doesn't find it there or if this variable is not set then IIS will look though your Windows system path.

figure 5


Brashquido's picture

For those of you that are

For those of you that are being prompted to download their php files rather than them being processes server side, double check you application mapping settings as per figure 9 above in the article. The ONLY way I have been able to successfully get IIS 5.1 to prompt to download a php file rather than process it is if the application mapping is incorrect. IIS will not let you save the mapping if the path to the php5isapi.dll is incorrect, so be sure that you have .php as the extension. If you have IIS Lockdown/URLScan installed, then you will need to add .php to the allowed extensions list.

Sorry about any spelling/grammar errors. I do my best, but unfortunately I am a product of the spell checker age and as the text editor on this site is very basic and doesn't have a spell checker there is bound to be the odd mistake that gets through. Feel free to point any mistakes out.

Anonymous's picture

This might be your problem

Brashquido, I believe I have my IIS and PHP5 set up correctly and this how I test it:


so for example I test my phpinfo.php page as follows:

http://localhost/ServerDir/phpinfo.php where ServerDir is my virtual server directory.

I think a lot of people are testing their pages like this:


so it would be like I was doing this:


This prompts me to download the .php file, if others are doing this just make sure you're testing it with the localhost url.


Brashquido's picture

That's a very good point

That's a very good point Brandon. For PHP scripts to be properly processed you need to access you PHP scripts via IIS, not windows explorer.

Anonymous's picture

Restart your server

Thanks for this excellent article Brashquido! I do have a newbie question though. When you say "Restart your server..", is it enough to stop and start the web services in IIS, or does the whole machine need to be rebooted?

Brashquido's picture

The main reason to restart

The main reason to restart your server is to update the environment varaibles. A restart might not be necessary, but it is one way to be sure the environment is refreshed properly upon install. Restarting your IIS services could well be enough. When you do it be sure that the Path variable from under the Environment section of the output of your phpinfo.php file contains the correct environment variables.

Anonymous's picture

Disabled Buttons

Hello Brashquido,
For some reason i could not add new mappings through the gui using iis5.0 because the OK button was disabled at the add menu in the configuration. But thanks to your great tutorial which points to a very nice script i could add the mapping. I have two more questions that i will be glad if you could answer. 1-Do you have an idea about why i am facing this strange problem about disabled buttons in the add mapping menu(i am new to web programming maybe its not strange but couldnt find info on the net)
2-My need was to add .html and php-cgi.exe mapping so that i could view embedded php. Now its working fine at last,but only for the root directory. So if i create a new virtual directory although it works for the root directory and i still see .html in the mappings for the new virtual directory, i cannot have the php code executed at the virtual directory- like in the initial situation.Why do you think this happens?
Thank you very much,

Anonymous's picture

Re: prompt for downloading .php file

I got the same problem as well. Upon inspection, i noticed that the Application mappings for the "Websites" (the one that was added to in this article) and the Application mappings in "Default Web Site" (under Websites) were inconsistent.

I fixed this problem, by following the same instructions in this article on doing the application mapping, except, i right clicked "Default Web Site" and selected Properties->Home Directoiry tab -> Configuration button and did the mapping from there.

Brashquido's picture

That's correct. If you add

That's correct. If you add your PHP application mapping at the root, then only websites created after you add the mapping will inherit the mapping. If you have existing websites you wish to use PHP on then you'll need to add a PHP application mapping at the site level.


At a guess I would say that buttons are grayed out due to a permissions issue. Not sure though as it has been a few years now since I'e worked with IIS 5.0 in depth. Make sure you are using a user account with full administrator privileges. Second issue sounds like your execute permissions are not set to enable cgi. This setting is in your virtual directory properties under the virtual directory tab. Make sure it is set to scripts and executables. If you have any further issues I'd appreciate it if you could post them in the forums so it does not fragment the comments discussion on this article. I'll be more than happy to help you out.

Anonymous's picture

where is the popup menu?

Hi Brashquido,
I'm so new to PHP. Hope you can help me. I'm testing a php website in my computer 1st using IIS (running windows XP Pro). I already installed PHP 5.2.3 & pec, learned from ur tutorial, & also the configuration. The website i'm testing is begin with index.php contains popup menu from other directory i.e. /gbl/inc/
But i cannot let go into index.php when typing "locahost" at Internet Explorer.
Or any settings i need set for that?

- William

Brashquido's picture

Hi William, I'm not 100%

Hi William,

I'm not 100% sure on exactly what you're asking, but from what I can gather is that you PHP app is not initialising a menu as it should. In the setup of some PHP apps you need to specify the URL the app will be served from, and if your app is accessed from any other URL then it might cause problems. Double check that you are accessing your app via the URL you specified during setup. You may need to add an entry to your hosts file so that the URL you specified resolves to your localhost, e.g resolves to