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

Brashquido's picture

Try FastCGI

A lot has changed since I wrote this guide 5 years ago. You are correct, phpisapi.dll has not been compiled for release with PHP since version 5.2. My advise would be to head over to http://windows.php.net and download the binaries from there. You'll also find links there to some of the PECL binaries compiled for use with later versions of PHP.

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

Anonymous's picture

Getting Not Authorized Error

I am getting following error:

You do not have permission to view this directory or page using the credentials you supplied
HTTP 401.3 - Access denied by ACL on resource
Internet Information Services

The problem occurs for php only,html and asp.net works fine.

Brashquido's picture

Check your NTFS permissions on PHP folder

That sounds like your IIS user does not have permissions to access the directory (or subdirectories) where PHP is installed. Your IIS user account will need read permissions in here.

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

Anonymous's picture

Can anyone here tell,, how to upgrade PHP?

Hello everyone,
I have PHP 5.2.1 installed already for about 3 years all running ok, but there are scripts that require higher version of PHP.
For the last 2 weeks I struggle and wrestle all with new versions of PHP to have running, it seems like it is really something hard to make it..
This new phenomenon requires wonder child from MS called fastcgi, good.
Can anyone tell us here how to upgrade to any version higher than PHP 5.2.4 ??
If you refer me to Google,, so I can tell you too, I spent a lot time and tried a lot tricks too,, nothing seems to work, when calling the webpags it says SERVICE UNAVAILABLE, additionally I can see in the IIS Manager ISAPI filters PHP red arrow, although it is set to fast cgi, fcgiext.dll
Thanks a lot for any advice,,

Brashquido's picture

Application mapping rather than filer

FastCGI should be configured as an application mapping rather than a filter. Did you have PHP 5.2.1 configured to use ISAPI?

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