Installing FastCGI & PHP5 on Windows Server 2008

· 9 Comments

25

Feb

Following my previous series of posts on how to install IIS7, PHP and MySQL on Windows Server 2008, Bill Staples from IIS.Net left a comment on my blog suggesting that I checkout FastCGI.

According to IIS.net…

the FastCGI component enables popular application frameworks like PHP be hosted on the IIS web server in a high-performance and reliable way.

Mike Volodarsky, a program manager on Microsoft’s IIS team, has expressed the following on his blog about why using PHP with FastCGI is the prefered method over ISAPI:

The main reason why ISAPI is not an adequate solution is the lack of thread safety in many popular PHP extensions.  The PHP core itself is thread safe, and so are some of the extensions, so its possible that some applications will work correctly in the ISAPI environment.  However, many production environments do experience instability with the ISAPI.

So that being said, let’s take a look at how to install configure the FastCGI extension to work with PHP 5.

Installing FastCGI And PHP on Windows Server 2008

As opposed to previous versions of Windows Server, the FastCGi module is already bundled with Windows Server 2008 so you don’t have to install it.

First of all, let’s make sure that the CGI role service is installed. Click on Start => Programs => Administrative Tools => Server Manager. Expand Roles, right-click on Web Server (IIS) and select Add Role Services. Make sure that CGI is checked and if not proceed with its installation.

iis7-cgi-role-service.jpg

Next head over to PHP.net’ download page and download the PHP Non-thread-safe Win32 binaries. At the time of this writing, the latest version of PHP is 5.2.5. Extract the content from the PHP archive into c:\php.

Launch the Internet Information Server Manager by clicking on Start => Programs => Administrative Tools => Internet Information Server Manager. Select your server from the left panel and then double-click on the Handler Mappings icon.

iis7-handler-mappings1.jpg

Click on Add Module Mapping from the right column:

iis-add-module-mapping.jpg

Fill-in the PHP module mapping information as illustrated below and click on OK when done:

iis-php-cgi-mapping.jpg

At this point PHP should now be working even though there no php.ini configuration file yet. To find out if PHP files are parsed correctly, create a new file at the root of website’s folder and name it phpinfo.php. Insert the following content into the file and save it:

<?php phpinfo(); ?>

Now try pointing your web browser to http://yourserver.com/phpinfo.php. If everything works properly you should see this page:

phpinfo.jpg

Configuring PHP

By default, IIS will look for PHP’s configuration file (php.ini) in c:\windows. To change this, launch the registry editor (Start => Run => regedit) and add a new key named PHP in HKEY_LOCAL_MACHINE\SOFTWARE\. Under the newly created key, create a new value named IniFilePath and set its value data to c:\php.

php-registry.jpg

Close the registry editor when you’re done. Using the Windows Explorer, rename c:\php\php.ini-recommended to c:\php\php.ini and open it with your favorite text editor (no word processor). Find the extension_dir parameter and set its value to “c:\php\ext”. You might also want to uncomment extension=php_mysqli.dll and / or extension=php_mssql.dll if you plan to use MySQL or MS-SQL.

Once you’re done editing PHP’s configuration file, save it and close your file editor. You will need to restart IIS in order to apply the changes. This can be done through the IIS Manager:

restart-iis.jpg

I’ll try to perform some benchmark test to see how this setup compares to using php5isapi.dll.

9 responses so far ↓

1. Response by : Ahmed on Feb 27, 2008 at 1:58 pm

Hi Stephane.. I tried to do as you say here but I think I have a problem..
it seems that I don’t have FastCGI in my laptop

I’m running vista ultimate 32-bit operation system 2006

I have installed IIS7 and I don’t know how to get the FastCGI for IIS7

when I choose add module mapping the window that pops has only three blanks input not four as in the pic here.. the Executable input is missing..

and in the module menu options there is no ((FastCGIModule))

I still can’t have the information about php with the code:

in the php file

they showed up only if I put this code:

PHP Information

does that mean I can not use it?

or I can just work fine with it?

thanks for help..

2. Response by : Ahmed on Feb 27, 2008 at 2:02 pm

the code doesn’t show up here, so I’ll delete some of it to make it show up:

html>
PHP Information

/body>
</html

3. Response by : Ahmed on Feb 27, 2008 at 2:04 pm

the first one is not complete

here it is:

html>
head>
title>PHP Information

body>
?php phpInfo(); ?>

</html

4. Response by : Stephane Brault on Feb 27, 2008 at 2:16 pm

Hi Ahmed,

First of all, FastCGI is installed by default on Windows 2008 but not any other version (Vista, 2000, 2003). I’ve got it installed on my home pc, I’ll look into this and I’ll post here soon.

And second, for the phpinfo.php file, you don’t need to put anything else than this code:

< ?php phpinfo(); ?>

5. Response by : Ahmed on Feb 27, 2008 at 2:57 pm

so do you think I have a problem with the installation?

don’t you think it’s gonna work?

I really need it to work cause I’m gonna begin my lessons from the day after tomorrow..

can’t I download the fastCGI from anywhere on the net?

thanks Stephane

6. Response by : Stephane Brault on Feb 27, 2008 at 8:56 pm

If the phpinfo() function doesn’t return anything, then no it’s not working.

Unless you are using Windows Server 2008, you have to install FastCGI manually.

You can get FastCGI for IIS6 here:
http://www.iis.net/downloads/default.aspx?tabid=34&g=6&i=1521

And FastCGI for IIS7 here:
http://www.iis.net/downloads/default.aspx?tabid=34&i=1299&g=6

I can’t tell you how to install it at this point but I’ll sure post about it someday.

Good luck!

7. Response by : Ahmed on Feb 28, 2008 at 8:02 am

thanks Stephane but the like of FastCGI for SII 7 says the page not found.. I think they already removed it..

and FastCGI for IIS6 can’t work on my machine..

I think I have to use apache instead of SII..
till I can get the new vista..

thank you a lot..

if you have any suggestions please let me know.. I’ll be here in whenever to see your work..

go ahead..

thanks again..
:)

8. Response by : Tasneem on May 12, 2008 at 1:30 pm

HI
On my development server, at home, I cannot get cgi scripts to work. Can you tell me how?
Thanks

9. Response by : Stephane Brault on May 14, 2008 at 7:23 am

Hi Tasneen,

I’ve posted the answer here: http://www.thewebhostinghero.com/articles/help-me-with-php-cgi-mysql.html

Hope this helps!

Leave a Comment




Posted in IIS · Tutorials · Windows Server | 9 Comments

 
   

Hosting Type :
Monthly Price :
Storage :
Transfer :
Platform :
Sort By :

Last Database Update: 2008-07-20


contact | about | privacy