Installing FastCGI & PHP5 on Windows Server 2008

February 25th, 2008 · 27 Comments

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.

27 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!

10. Response by : Nelson on Aug 1, 2008 at 2:51 am

Is working thanks for teh info

11. Response by : websologist on Sep 23, 2008 at 4:33 pm

I cant even get the IIS 7 page to display. Spent all day on this. You did in 6 minutes.

12. Response by : Stephane Brault on Sep 23, 2008 at 4:35 pm

Hey Websologist,

Did you manage to finally make it work?

13. Response by : Nelson Leung on Jan 22, 2009 at 3:10 am

Great !!!
I follow your instructions and I have solved my problems.

14. Response by : Dana on Jan 23, 2009 at 10:34 pm

Hi Stephane;

Thanks for this tutorial. I think I’ve got PHP running on my server now. Following your suggestions to the letter did not work. I had to change the handler mappings on the default website to get the phpinfo.php file to run.

Thanks again.
d

15. Response by : Dana on Jan 23, 2009 at 10:38 pm

oops, might have figured out why your suggestion didn’t work. Seems I’m only running IIS6

16. Response by : Daniel on Feb 2, 2009 at 8:33 pm

Windows 2008 Standard
I had to add a Handler to the Default Web Site to get this to work. My guess is that the global setting only works on sites that haven’t been created yet.

Thanks for the tutorial

17. Response by : Lonestarjack on Feb 7, 2009 at 9:04 am

Vista, sp1:
I have followed your directions. Even reinstalled php 5.2.6. No matter what I do I keep geting failures that sayu “bad isapi module in list” or “can’t find isapi module:.
My question is — where is it called out to use isapi instead of fastcgi?

18. Response by : Stephane Brault on Feb 9, 2009 at 3:27 pm

Unfortunately I don’t have my Windows 2008 Server anymore but on Windows 2003, you will find the ISAPI filters under Web Sites > Properties > ISAPI Filters

19. Response by : lonestarjack on Feb 11, 2009 at 8:28 pm

Wow!After 2 months I finally can run PHP on my laptop. I didn’t understand that there are multiple places to change the module mapping info.
I was on the verge of reinstalling Vista because I thout the registry was messed up.

20. Response by : Corey Gouker’s Machine Inside the Mind » Blog Archive » On migrating to WordPress from dasBlog… on Feb 12, 2009 at 1:26 pm

[...] Remember to set the PHP registry settings if you extract PHP from the ZIP http://www.thewebhostinghero.com/tutorials/windows2008-iis7-fastcgi-php.html [...]

21. Response by : Carlos on Jun 2, 2009 at 3:18 pm

Whats wrong with just plain CGI?

My admin installed php-cgi.exe (v 5.2.9.9)
on Win 2008 IIS7

Should I reinstall to get the FastCGI?

22. Response by : Stephane Brault on Jun 3, 2009 at 8:52 am

Hi Carlos,

There’s nothing really wrong with using PHP as a CGI although you’ll gain more performance with FastCGI.

Stephane

23. Response by : marks on Sep 17, 2009 at 8:48 am

Well it works! but… at the beginning u must first made Web Servver ISS (if u dont have so…) and after this make CGI. :) I am using also web expression 2 Good Luck! It took me only 10 minutes coz I am beginner in this environment.

24. Response by : ex3m on Feb 13, 2010 at 5:05 am

its work fine thnx

in phpinfo.php no need enything else

?php phpInfo(); ?>

no need all of this configuration

you can find installer of PHP5:

“php-5.3.1-nts-Win32-VC9-x86″

or whatever is your machine preformance
an all you need to config is

regedit and crating phpinfo.php

*sorry for my language*

25. Response by : Wentao Su on Apr 19, 2010 at 8:40 pm

To those who get the error message “The FastCGI process exited unexpectedly” and trying to use php 5.3.2, pls try the following:

add a line in php.ini like date.timezone = “GMT”, and it should work.

For more timezone format at:
http://php.net/manual/en/timezones.php

26. Response by : Terry on Jun 5, 2010 at 12:52 pm

I keep receiving the HTTP 500 Internal Server Error when I try running a PHP file on my Windows Server 2008 machine. The php file I am attempting to use is supposed to open a text file located within the same directory as my website and the php file. When I run the phpinfo.php file, it loads fine without any problems. Here is the php contents that do not seem to work for me:

27. Response by : Orazio on Jul 27, 2010 at 3:29 am

I’m receiving the HTTP 500 Internal Server Error too, error is located in php5ts.dll module.
If I disable extensions in PHP.INI, phpinfo.php works correctly.
I checked the extensions path and it is correctly set (c:\php\ext).
If i doubleclick on php-cgi.exe, I receive the same error (if extensions are enabled in php.ini).
What can I do? Thanks

Leave a Comment




 
 
 
 
 

Tutorials by Category

 
 

Recent Comments

 
© Copyright 2010 - TheWebHostingHero.com