Installing PHP 5 on IIS in 5 simple steps

Categories:

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

Comments

Anonymous's picture

php.ini - missing line causes file download prompt and so on...


As far as I can see, the only thing that's missing is another change to the php.ini file regarding cgi.force_redirect setting.

The value MUST be set to zero. The php.ini file reads:

"cgi.force_redirect is necessary to provide security running PHP as a CGI under most web servers. Left undefined, PHP turns this on by default. You can turn it off here AT YOUR OWN RISK
**You CAN safely turn this off for IIS, in fact, you MUST.**"

Before I changed that setting, I had the same problem as a lot of people writing comments here: prompt for file download instead of displaying the page when using a web browser to connect to http://localhost.

I went through a couple of guides and none of them worked for my system. I am using Win XP with IIS 5.1 and I've tried to follow the manual installation steps described on the PHP site but it didn't work for me.

I just couldn't get FastCGI to work with PHP 5.3.3 no matter how hard I tried. I did everything by the book several times, nothing... When I chose php-cgi.exe for the executable - it worked but I wasn't sure if that's the way to go, so I decided to try it with your instructions.

Seems to be working fine, except for that initial

Anonymous's picture

how to put the file in website

Hi
i created phpinfo.php file using notepad.But how to place it in website and test using web browser.

Thanks
john

Brashquido's picture

FTP

Hi John,

Usually you'd use something like FTP to upload your files to your webserver. Ultimatley it depends on how you connect to your server though. I'd recommend contacting your host to determine which method to use.

----------------
Dominic Ryan
6 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster

Anonymous's picture

IIS 5.1 being prompted to download .php

I spent a couple of days trying to get PHP 5.3 and FastCGI working with IIS 5.1. Symptom: it would hang, it would be blank, it would prompt for download depending on how I tinkered. The catch? I was doing the Mapping (.php to fcgiext.dll) correctly in IIS except applying it to the Web Sites folder instead of Default Web Site which is one below that in the IIS listing. I gather Default Web Site is the one that corresponds to where I have phpinfo.php test file with and I had been assuming subdirectories inherit the mappings automatically. Not so. I also had a problem with the OK button being grayed out when browsing for the mapping dll - and found you just need to click your mouse in the text box where the path is.

Anonymous's picture

Prompted to download the phpinfo.php file

I was having this problem with PHP Version 5.2.17, all I had to do was change the configuration and setting the php5isapi.dll on page 3 for each of my IIS website virtual directories that I have already made before installing PHP. (remember to restart IIS afterwards)

Thanks a great tutorial on PHP...

Anonymous's picture

Many thanks, Fantastic post.

Many thanks, Fantastic post. The best I have seen regarding installing and configuring PHP and MySQL for IIS.
I have installed everything as your instructions and it is working perfectly.

Although I do have an issue with OWA and activesync that you may be able to help with.

I am using SBS2003 on the IIS default web site.

Before installing Wordpress, PHP and MySQL, OWA and activesync were working fine. After installing Wordpress, PHP and MySQL, both OWA and activesync will not accept the login credentials. Index.php and PHP are affecting the default home documents of the default web site, everything is run through index.php.

To problem solve the issue, I have created two Home Directory folders for the default web site, one with the default setup (including default.htm, default.asp, index.htm, default.aspx) and the other with default setup AND the wordpress .php files. When I set the local path of the home directory to the folder that contains the .php files, our PHP web site functions perfectly BUT the OWA and activesync will not accept the login credentials. If I change the home directory to the folder that does NOT contains the .php files, OWA and activesync both function perfectly, but obviously our PHP web site does not function tech talks.

Any suggestions?????

Anonymous's picture

Top man

Great guide, thx a lot.

Anonymous's picture

PHP5 + IIS5

This was a good guide to have PHP up and running on IIS, but I have done this all, but unable to get the PHP page to work. It shows the error as
"The page cannot be displayed
There is a problem with a program on the page you are trying to reach, and the page cannot be displayed."

I had this PHP running previously, until I re-installed the OS(XP), can't get this to work. I installed PHP, configured env variables, set the mapping to 'php5isapi.dll', set all the paths in php.ini, but no luck as well as no sensible errors. Can't decide, where to start searching. It is as if the PHP.ini is not being recognized, even though it is present only in 'wwwroot'. Tried mapping to 'php-cgi.exe', and force redirect to 0; still no go.

Need help or what am I doing wrong ?

Anonymous's picture

PHP5 + IIS5

This is to add to my last post, where I was not able to get PHP running and got the error as 'The page cannot be displayed'.

This turns out to be execute permissions to be set in IIS. Somehow this keeps reverting back to 'none' when a php page is accessed, leading to the error. I guess if you have done everything right, checking the IIS configuration would definitely save a lot of hair and time rather than tampering with the PHP installation.

Also, the php.ini path seems to be bouncing around between C:/Windows and the installation path of the PHP. Not sure what is causing this though...

Brashquido's picture

IIS applications and/or multiple PHP installs?

Sounds like a bit of a headache. This sort of behaviour can be caused by a few things, my guess would be something like there being multiple PHP mappings in IIS as well as possibly multiple instances of PHP. Honestly you can spend hours trying to fault find these sorts of errors, and being a Windows 2000 server I'm guessing this is not a new install. My advice would be to start from scratch by doing a full uninstall of PHP on IIS, and in doing so you are ensuring your IIS environment is as clean as you can realistcally get it before installing PHP.

----------------
Dominic Ryan
6 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster