Configure PHP on IIS with FastCGI

Posted on March 11, 2009


A few days ago, I purchased a VPS with Windows Server 2003 R2 installed. It has been quite sometimes for me to not touch Windows Server things. I love telnet and SSH connection to all my UNIX and Linux servers, but I would like to give Windows Server a second try, well… more precisely, I would like to give Microsoft .NET a second try.

I used the VPS for web development (PHP) and Microsoft .NET experiment machine. The machine was given empty, so I started to fill it with my stuff, and one of them is PHP with FastCGI. I understand the main benefits of FastCGI, which are distributed computing and multiple roles. Frankly, I don not really need those benefits, but it is good to know that I have something more. For instance, I have a car that can speed up to 160 mph, even though I am too scared to reach that level, I feel happy to purchase that car, knowing that I have something more.

As usual, I started from Google, searching php on iis. I get this website in the first rank: The guide in the website was very clear and I managed to have my PHP run on the first try. Anyway, these are what I did:

  1. Unlike IIS7, IIS6 has no built-in FastCGI. I downloaded and installed FastCGI Extension for IIS6.
  2. I downloaded and installed the latest PHP 5.x. I actually found out that the PHP installer was able to configure the FastCGI for me. Good job!
  3. I went into C:\windows\system32\inetsrv through CMD and performed:
    cscript fcgiconfig.js -add -section:"PHP" -extension:php -path:"C:\PHP\php-cgi.exe"
  4. I verified that the installer also updated the default document in my web server. It added in index.php.
  5. I followed the instruction to optimize my PHP from php.ini file:
    fastcgi.impersonate = 1
    cgi.force_redirect = 0

    I also came back to the C:\windows\system32\inetsrv through CMD and performed:

    cscript fcgiconfig.js -set -section:"PHP" -InstanceMaxRequests:10000
    cscript fcgiconfig.js -set -section:"PHP" -EnvironmentVars:PHP_FCGI_MAX_REQUESTS:10000
  6. Finally, I wrote my PHP script in C:\inetpub\wwwroot\ and called the script from a web browser. And it worked!

I guess if I use IIS7, I can omit step number 1. I am not really sure though.

Posted in: MyWay