Installing PHP 5 on IIS in 5 simple steps

Categories:

Configure PHP.ini

You could very easily write a series of articles regarding setting the various php.ini directives, so to try and keep this article short I will just deal with the basics here. When serving PHP on IIS the php.ini file is the only place that options are set, and if no php.ini file can be found then the defaults are loaded. The limitation of a single php configuration for an entire server is perhaps one of the biggest disadvantages with hosting PHP applications on IIS, especially in shared hosting environments.

There are actually only a handful of setting you will might want to look at configuring in php.ini, and they are the path to your extensions, sessions, and upload directories. You'll also may wish to enabled a few PHP extensions to get added functionality from PHP that might be required by some PHP apps, and perhaps set some PHP logging options.

  • Open your PHP installation directory (e.g D:\PHP) and copy php.ini-recommended and rename the copy to php.ini
  • Open php.ini and do a search for extension_dir = "./" and replace it with extension_dir = "D:\PHP\ext" where D:\PHP\ext is the path to your extensions directory (it's the one with all the files that begin with "php_" in it). The path to your PHP installation will be used for the next several steps, so take care that you modify them to suit your own environment.
  • Search for ;session.save_path = "/tmp" and replace it with session.save_path = "D:\PHP\sessions" (note the semi colon (;) is removed). This will be used to store PHP session information which is used by many PHP applications.
  • Search for ;upload_tmp_dir = and replace it with upload_tmp_dir = "D:\PHP\upload" (note the semi colon (;) is removed). This is used for all your HTTP upload files, and if not set your system temp will be used.
  • Search for ;error_log = filename and replace with error_log = "D:\PHP\log\php.log" (note the semi colon (;) is removed). This is where all your PHP logging information is kept when enabled. You can also configure PHP to log data to your Event Log, but it requires loosening the privileges on the IUSR_COMPUTERNAME account IIS uses.
  • Search for ;extension=php_mysql.dll and remove the semi colan (;) from infront of it so it appears as extension=php_mysql.dll. You'll almost certainly need this PHP extension loaded as any PHP application that uses the MySQL database will need it.

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