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

Installing PEAR on PHP5

Thanks for answering my pervious post. I reinstalled PHP4 and used your IIS-AID, however that did not work.

Uninstalled it again. and Installed PHP5 per your instructions. Worked like charm. However, the software i want to install is called VTCalendar, http://vtcalendar.sourceforge.net/index.php, I followed the instructions but can not get it to work. It requires PEAR to be installed as well.

I'm assuming PEAR is out of the box ready in PHP5, do you have any resources in installing PEAR on my WIndows 2003 Server?

Thanks
Ricky

BeachBoy's picture

What's the best extensions to enable for PHP on IIS?

Dominic,

I'm curious about one thing regarding extensions for PHP 5.2.3 on Windows XP using IIS 5.1... Which extensions do you recommend that someone enable in their PHP.ini file for the best functionality for most PHP based applications? I plan to use Drupal 5.2 as mentioned in my previous post, as well as some other tools (CiviCRM, a OpenID server, etc...). If you could recommend some extensions (or write a article on the subject), it would be very helpful to me and others interested in using PHP 5. Also, please explain what the Pear libraries are used for, and where do we (I) download them, install them in PHP and so on.

Thanks in advance
~ BeachBoy

Brashquido's picture

@ Ricky Installing PEAR

@ Ricky

Installing PEAR should be as simple as opening up a command prompt, navigating to the root directory of your PHP install, and executing the go-pear.bat batch file. From there just answer the questions and you should be set.

@ BeachBoy

Enabling PHP extensions for IIS when using PHP as an ISAPI module is where things get a bit tricky, and you certainly do not want to go enabling PHP extensions unless there is a specific need. This is because a lot of PHP extensions are designed with the *nix multi process model in mind, where Windows/IIS uses a multi threaded model. This can cause major stability issues when using PHP extension that are not thread safe on Windows. Currently the only real viable way around this with PHP5 is to configure IIS to use PHP in CGI mode which is not effected by this, but this comes at the expense of a major performance hit (even using the new non thread safe binaries that significantly increase PHP CGI performance). If a PHP application requires a specific PHP extensions, then it will usually specify what one(s) it needs in its requirements documentation.

As for PEAR, have a read through the Wikipedia entry for more details. The PEAR package manager is included with the Windows distribution packages for PHP, and can be installed as per instructions above for Ricky. Again, if a web app requires a particular PEAR package, then that should be specified in the requirements documentation.
----------------
Dominic Ryan
3 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster

BeachBoy's picture

Woohoo! It works like a charm (so far)

Dominic,

Thanks for a very easy to follow install guide... I've now got my IIS Server setup for PHP, and I'm quite happy with the results. I don't know if anyone has mentioned this, but if you wish to use a PHP app that has an index.php file, you should set the Default Document section of the IIS manager to reflect this. Make sure you add it, then move it up the list before the iisstart.asp entry.

Regarding Pear, I'll be adding that as I need it. Now I'm off to test Drupal...

~Beach Boy

Anonymous's picture

Thaks for a great guide!!!

But i followed it to a tee. However when i pull up the http://localhost/phpinfo.php page it doesn't error out it just says done in the left corner of IE. It does nothing. Any Ideas? Thanks again for the detailed guide and any help you can offer.

Jason

Brashquido's picture

Ok, what version of windows

Ok, what version of windows are you using? Can you scan your IIS logs for phpinfo.php and post back the entire line if you find it?
----------------
Dominic Ryan
3 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster

Anonymous's picture

Great GUIDE!! Just facing one problem...

Hi Brashquido,

Thanks for the wonderful step-by-step guide. I'm still having a problem with the prompt that wants to download the file rather that run it. I've checked the MAPPING settings and they are correct. I also tried using:
http://localhost:8020/phpinfo.php BUT it wants to save the file. Other html files work fine though.

Any ideas?

Thanks

Anonymous's picture

PHP Code shows up in browser!!

Thanks for the great guide, but when I try the PHP test the code shows up instead of the page. It's like nothing gets processed.

I tried the small code you suggest and the same thing happens.

Thanks in advance

Anonymous's picture

Great Guide!!

Thank you very much!! This has been my 5th attempt at configuring IIS and PHP. After all the rubbish advice from the first search results in google, i hit the next button about 15 time and found your site! Thank goodness!!

Again, many thanks for the advice!

Damien

Brashquido's picture

If you are being prompted to

If you are being prompted to download php files rather than them being processed, then I'll stongly suspect that it is your application mapping. I know you said you've check it, but it is the only way I've ever been able to reproduce this problem. Double and triple check this, and if the problem continues feel free to send me a private message or use the website contact form to get in contact me as if the application mapping is not the issue I am as keen to find a resolution as you are.

As for php code being displayed in the browser window rather than being processed, then double check that your php code is enclosed in the proper php tags. Your php scripts may also be configure to use short tags, and if so you'll need to enable the short tag option in php.ini or modifiy your scripts to use the full php tags.

Thanks for the kudos Damien, glad to know the guide helped :)
----------------
Dominic Ryan
3 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster