Install PHP FastCGI MySql and PHPMyAdmin On IIS6

This is just a note to remind myself the process of installing PHP,MySql and PHPMyAdmin on IIS6 and Windows Server 2003. If it is of any use to you, that will be great.
There are many ways to run php and mysql stack on windows, if you are from a background of linux, or as a windows user you want to explore apache web server a bit, then you might prefer wamp or xamp, if you are a hard core windows user, you can run php applications pretty much the same way as an asp.net application on IIS.

The easiest way of installing php and mysql on IIS is using windows installer, but if you want to know more about how these applications work together, you can get your hands dirty by going through all these steps manually like what I have done.

My understanding is there are two ways to run php on IIS, one is through phpisapi.dll which is simpler to set up and easier to understand, as it is in line of principles of extending IIS functions by adding new file handlers, but obviously to run a php application on IIS is more than an extra file handler, that is why experts recommend to use FastCGI as the preferred option to run php on IIS, actually the latest php(5.3.3) even does not have a phpisapi.dll any more.

1. For IIS 7 or newer, FastCGI support has been built in, just need to be enabled, but for older IIS, you need to go to http://www.iis.net/download/fastcgi to download and install fastcgi extension.

2. Download None thread safe php windows binary zip file from http://windows.php.net/download. As IIS has built in multi thread support for web applications, in php we do not need any thread management at all, that is why we choose NTS version of php.

3. Unzip the file, rename php.ini-production to php.ini
4. Make following changes

fastcgi.impersonate = 1
cgi.fix_pathinfo=1
cgi.force_redirect =0
open_basedir =”C:\Inetpub;C:\anotherfolder;”
log_errors=on
error_log =”C:\Inetpub\logs\php-errors.log”
extension_dir = “.\ext”
session.save_path = “C:\Inetpub\PHPSession\”

open_basedir is very important here, visits outside of this dir will trigger an error:
open_basedir restriction in effect… is not within the allowed path(s).

To turn on the log function is also important in terms of debugging and trouble shooting.

5. Go to c:\windows\system32\inetsrv, open fcgiext.ini file with notepad and add following entries :

[Types]
php=PHP
[PHP]
ExePath=c:\php\php-cgi.exe
Make sure that the path of php folder is your one, this is to hook up fastcgi with php engine

6. In IIS manager, right click your php web site (in my case , I run all my php applications on a special port 8091), properties-home directory-configuration- add mappings like this:

Executable :c:\windows\system32\inetsrv\fcgiext.dll
Extension : .php
Verbs limit to: GET,HEAD,POST
Check both Script Engine and Verify that file exists.

To add index.php to Default Content Page list.

7. Call phpinfo() in your test.php to double check all your configurations, bang! You get
FastCGI error, Error Number 5, Error Description : Access is denied. This error is not documented very much on the internet. The error is that the IIS account does not have the permission to read and execute php-cgi.exe.

You can find out the IIS account through IIS manager-Application pools- your php application pool- properties- identity, as default the account is ‘Network Service’.

To check who has the permission on your php folder, right click your php folder, normally only administrator and system account are given the permission, just add ‘Network Service’ to the list with permission of read and execute.

Run test.php again, you will be awarded with the famous phpinfo page.

8. There are a lot of articles out there describing how to install MySql, so it is not repeated here.

9. After MySql(5.1.5 Community) is installed on your server, you need change your php.ini, to enable MySql extension :

extension=php_mysql.dll

Some articles mentioned copying libmysql.dll to either windows or windows system32 directory, and in my case it is not necessary at all, my understanding is MySql is being run as a service(recommended as best practice-Install As Windows Service).

Together with MySql extension, enable following extensions as well in php.ini

extension=php_gd2.dll
extension=php_mbstring.dll

10.Run phpinfo() again to check the presence of ‘mysqlnd’(MySql native driver).

11. Install phpMyAdmin, download all language zip file of latest version, unzip it, create a virtual directory under php site in IIS manager. If the folder is not in open_basedir, you can include the phpmyadmin folder within php.ini open_basedir entry separating it from other dirs with semi colon.

12. Rename config.sample.inc.php to config.inc.php
13. The only configuration you need to change is : $cfg[‘blowfish_secret’] = ‘mysecretkey’, this is the key to encrypt the session. I will use root account to login MySql, so no need to change other settings.

That is all I have done to make whole stack working in my environment, in other words, things that are not mentioned here basically are not needed, that is one of my purpose of writing this article to document only those absolutely necessary steps and configurations that are required for whole php stack to work on IIS.

Added on 22/09/2010 1:
If your application allows the anonymous access and IIS impersonate is on which is true for most php apps, then the NTFS read and execute permission on directory of this anonymous account must be granted as well. This is not to be confused with IIS service account Network Service and its access to php engine, IIS needs access to php engine, and on top of that, IIS redirects anoymous request to your php application using the anonymous account because fastcgi.impersonate is on.

Added on 22/09/2010 2:
In phpmyadmin, you might want to restore database from a datadump sql file, and you get error:

No data was received to import. Either no file name was submitted, or the file
size exceeded the maximum size permitted by your PHP configuration. See FAQ 1.16.

When I had a look of my php error log file:

File upload error – unable to create a temporary file in Unknown

So it is nothing to do with the file size issue as suggested by phpmyadmin error message, but a more general issue of file uploading of all php applicaiton.

The issue is we have not set upload_tmp_dir in php.ini, and instead php engine is trying to use system temp which is C:\WINDOWS\TEMP\ and php worker process does not have write permission to.

Solution is : update php.ini with

upload_tmp_dir =”C:\Inetpub\temp”

Again you can see how important the error logging is to our swift trouble shooting.

Tags:

This entry was posted on Tuesday, September 21st, 2010 at 4:00 am and is filed under PHP. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

7 Responses to “Install PHP FastCGI MySql and PHPMyAdmin On IIS6”

  1. blog bookmarked and stumbled upon, I’ll post my feedback on my blog asap

  2. Great, thanks for sharing this article post.Really looking forward to read more. Awesome.

  3. Cool Post I will be checking back

  4. Thanks for your excellent article and very good blog I was extremely blown away seriously!

  5. Thanks, I bookmarked your website and will come back later.

  6. Demetrius says:

    Great post! We are linking to this great post
    on our site. Keep up the great writing.

Leave a Reply

*