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

Thanks

Just wanted to say thanks for taking the time to write this tutorial. I installed php and mysql with apache before, but it's been a while, and I'd never worked with IIS before until recently. This was a great tutorial to get me up and running quickly, everything worked like a charm.

Anonymous's picture

http 500 error

I followed steps above to install PHP 5.2.3 for IIS 5.1. But when I test it, I got HTTP 500 error. Any solution?

Brashquido's picture

A 500 error could be caused

A 500 error could be caused by a few things. Most immediate one that comes to mind as I had to deal with it just the other day is the fastcgi.impersonate setting in your php.ini file is set to 1.

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

Anonymous's picture

Uninstall PHP 5

Great article. I had PHP 4 installed, but the PEAR option was not installed. So I thought to Uninstall and install a version that had PEAR. Everything was working fine PHP4. I uninstalled, reboot, and then reinstall PHP5 using the MSI installer. However, my PHP webpages came back with an 404 error.

Whats the best way to uninstall and remove all PHP related files from my Win2003 server? and to a complete reinstall following your instruction.

Thanks.
Ricky

Brashquido's picture

Might be worth double

Might be worth double checking that you enabled a web service extension for PHP5 before we look at removing all things PHP from your system. Without knowing how PHP has been installed on your system there is very little chance of me being able to tell you exactly where and what to look for, but I can give you a general guide;

1) Ensure paths referencing PHP are removed from the PATH variable
2) Delete all PHP files
3) Check your windows system directories for PHP files which are sometimes copied over from the PHP directory when the PHP paths are not set correctly during setup.
4) Delete all PHP web service extensions from IIS
5) Delete all PHP application mappings from IIS

That should about cover all the obvious ones I can think of for now...

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

Anonymous's picture

a perfect worl a perfect guide

I NEVER write comments on these sites. For your guide I had to. VERY good job. 7th instruction set. Worked like a CHARM

Anonymous's picture

Very strange PHP session problem on IIS5, IIS6

Hi Ryan,
i installed PHP on my IIS5 (XP Pro), IIS6 ( win2k3 server SP2 R2) , everything works fine, except PHP session.
my server IP is 192.168.1.60
test.php
< ?
session_start();
?>
if i open this test.php like this: http://localhost/myweb/test.php, no error occur, but if i open the test.php like this: http://192.168.1.60/myvdir/test.php, it says:

Warning: session_start() [function.session-start]: open(C:\WINDOWS\TEMP\\sess_ii5515gqj838mhpugm5lr267e2, O_RDWR) failed: Permission denied (13) in C:\MyWeb\test.php on line 2

Warning: Unknown: open(C:\WINDOWS\TEMP\\sess_ii5515gqj838mhpugm5lr267e2, O_RDWR) failed: Permission denied (13) in Unknown on line 0

Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct () in Unknown on line 0

any idear?
Thanks.

Jaive

Brashquido's picture

Hi Jaive, Can you open your

Hi Jaive,

Can you open your php.ini file and find the line with the session.save_path directive in it? Once you've found it post back here with the entire line.
----------------
Dominic Ryan
3 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster

BeachBoy's picture

Newbie questions

Hello Dominic,

I have a few questions as a newbie using IIS and PHP 5.2.x for you. I'm just getting started using IIS as a subdomain of my site (http://xtra.thecafeunderground.net), mostly because my hosting provider is running the main site on Linux w/ Apache, PHP 4.3.1, and MySQL 4/5. I wanted a testbed for Drupal 5.2, and I've already got a SSL certificate installed (from CACert). My questions for you are as follows:

1. If I install PHP 5 per your instructions in the how-to, can I use a preconfigured PHP.ini file (for example, the one created using the IIS-AID installer after I remove the PHP 4 install)?

2. Do you recommend using any other tools for the testbed server besides PHP and MySQL? If so, are any of them open-source or free?

3. Do you have any other tips for a newbie wishing to use Drupal on IIS?

Please feel free to contact me when you can. Thanks in advance.

~ BeachBoy

Brashquido's picture

Hi BeachBoy, 1) Mostly, but

Hi BeachBoy,

1) Mostly, but there are a few differences between PHP 4 and 5. For instance the MySQL client is loaded automatically in PHP4, but loaded separately as a PHP extension in PHP5. There also might be issues with paths and things. It could be done, but I'd think there would be fewer issues with just altering the existing PHP5 ini file.

2) Depends totally on what you want to do. PHP is by far the most popular open source scripting language around at the moment, and as such most open source web apps utilize this language. About the only other "must have" I'd say you need there is Perl (check out Activestate), and maybe if you're feeling like it RoR. Obviously you could also look into .NET for running web apps such as Dot Net Nuke.

3) Make sure you backup and just spend time with it. Only other Drupal specific thing I'd recommend you look at is Clean URL's (such as use on this site). There are presently only a few offerings for IIS that enable you to manipulate URLS to create this effect. I'd recommend having a look at Helicon ISAPI Rewrite Lite which is free, and then check out my guide in the "how to guides" section.

Let me know if I can be of any more help.

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