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

Blank page

When I try test page phpinfo.php I can see only a blank page.
display_errors directive in php.ini is already turned on.
Any help please
Jos

Brashquido's picture

The only way I've ever being

The only way I've ever being able to reproduce the problem where PHP code shows up in the browser is when the PHP tags are missing, not correct, or the short tags directive not being enabled in php.ini in instances where code is using short tags. It seems that you do have you PHP tags there, so I would go back and double check that there are no spaces in the opening or closing tags.

Blank pages are slightly more common, and when doing a simple phpinfo test usually come about because the PHP application mapping has not being setup correctly. I'd suggest going back through the guide from step two and double check all your settings.
----------------
Dominic Ryan
3 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster

Anonymous's picture

php.log

HI!

This is a great instruction.
Everything is working except some things.
I am using PHP 5.2.4, IIS 5.1, XP Pro SP2.

I hate that, if i change anything in php.ini, i should restart the whole OS, but this is the smallest problem.

I did set up evertything as you sad:
in my php.ini:
display_errors=On
log_errors=On
error_log = "D:\PHP\log\php.log"

with theese settings, if i make an error in a file, the apache server write the php.log.
But not the IIS. My file is there, but when an error occured, that is not writing anything into the file >:(

Vaso

Brashquido's picture

Hi Vaso, You really

Hi Vaso,

You really shouldn't have to restart the OS for changes in php.ini. A restart of IIS should be enough here. As for your PHP log there are a few thing you could possibly check;

1) Have a look at your phpinfo page and make sure the correct path to you log is set.

2) You may need to grant the NTFS write permission to your log file for the IIS user account (IUSR_COMPUTERNAME).

3) Download the filemon utility and set it to monitor your log file which should give you a very good indication on where things are going wrong.

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

Anonymous's picture

THANK YOU!!!

I have been trying for days to get php5 installed on IIS5. It felt like a tried everything until I stumbled across this article. I followed the 5 easy steps and "wah lah" it worked. You are awesome. Thank you very much!!!

Anonymous's picture

:D

Yeeeeeeeeeeeeeeees
Finaaly!

Anonymous's picture

Hello there...

I have been tired with the times i have tried installing php 5 and finally i was able to do it easily with your instructions and quite successfully i tested phpinfo() files as well. Thank you for that...but still i hav that problem of opening files as to download when they are being tried to open via an html file... for eg : i want to open a run a php script which is written in a file called result.php and need to run in when the submit button of html page is pressed. but here as it is clicked it tries to download the file rather than running the script. i checked the mapping as u said and in the add filter i tried adding php but it says its not loaded and thats not working fine... what should i do to solve this problem.
please help me...

Brashquido's picture

First, PHP should not be

First, PHP should not be loaded as a filter, it should be loaded as an application mapping. I recommend having a look at the "Set the PHP Application Mapping in IIS" section again. What happens if you access this results.php file directly rather than calling it via your form?
----------------
Dominic Ryan
3 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster

Anonymous's picture

Http 500 error message for

Http 500 error message for all php pages... i installed in the same way as u said...

Brashquido's picture

500 is an internal server

500 is an internal server error, so there must be something amiss with your PHP environment. Can you check;

1) Make sure there are no spaces in the path in your PHP application mapping.

2) Did you add PHP to your PATH variable

3) Did you create the PHPRC variable?

4) What PECL extensions do you have enabled?

5) Are you able to execute a simple phpinfo page as described in the guide?
----------------
Dominic Ryan
3 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster