Pluralsight blog Where devs, IT admins & creative pros go for news, tips, videos and more.
Pluralsight + Digital-Tutors - 3,000 tech & creative courses - starting at $29/month Get it now →
September 4, 2008

IIS 7: Install FastCGI PHP on Server 2008

By

One of the major advantages that the Apache web server enjoyed over IIS for years has been the native support for PHP. Most Windows Hosting you get will, if you’re lucky, install PHP for you but not support it at best.

This left some of the best open source programs out there too much of a hassle for most users. With the release of the FastCGI module you can now reliably host PHP programs on IIS.

Let’s go ahead and walk through installing the Fast CGI Module and PHP.

How to Install FastCGI on Server 2008

A few prerequisites for installing FastCGI would seem obvious but let’s go ahead and mention them anyway.

The first of course is an installation of Server 2008 (though this works on Vista if you are so inclined) and having IIS 7 installed already. You can also enable FastCGI while installing IIS, but for this demo I already have a virtual server with IIS 7 installed so let’s go with that.

If you need help installing the web server you can read my article on Installing IIS 7. Now let’s start:

1. Open Server Manager.

2. In the left pane expand Roles and click Web Server (IIS), then in the center pane scroll down and click Add Role Services.

IIS 7: Install FastCGI and PHP on Server 2008 - 1

3. Next on the Select Role Services screen select CGI, under Application Development, then click Next.

IIS 7: Install FastCGI and PHP on Server 2008 - 2

4. Confirm Installation Selections by reviewing the options you picked and then click Install.

IIS 7: Install FastCGI and PHP on Server 2008 - 3

5. You should see Installation Succeeded on the Installation Results screen; go ahead and click Close.

IIS 7: Install FastCGI and PHP on Server 2008 - 4

6. You will now see the CGI role service under the IIS panel.

IIS 7: Install FastCGI and PHP on Server 2008 - 5

Now that wasn’t too bad was it? You will notice that you installed CGI instead of FastCGI, but by selecting CGI it enables both. Now let’s move on to installing PHP!

How to Install PHP on IIS 7

When dealing with PHP there are many different versions that are in use and depending on the application you are going to be using you may need a specific version. There are also repackaged versions like those from Zend that are pre-packaged and optimized extensions that work together.

If you want to use the official release you can get it from: http://www.php.net/downloads.php

For this demo I am going to use PHP 5.2.6 Non-thread-safe installer under Windows Binaries. It is recommended to use the non-thread safe build with IIS 7 since FastCGI will ensure single threaded execution environment.

Once you download it to your server let’s get started.

1. Left click on the PHP Installer Binary.

IIS 7: Install FastCGI and PHP on Server 2008 - 6

2. You will now see the PHP Setup Wizard window, go ahead and click Next.

IIS 7: Install FastCGI and PHP on Server 2008 - 7

3. On the End-User License Agreement, go ahead and place a check in the box accepting the terms in the License Agreement and then click Next.

IIS 7: Install FastCGI and PHP on Server 2008 - 8

4. Now select a destination folder, for our example I am going to use C:\PHP5\, type or navigate to where you want to install it and click Next.

IIS 7: Install FastCGI and PHP on Server 2008 - 9

5. Now select IIS FastCGI as the web server and click Next.

IIS 7: Install FastCGI and PHP on Server 2008 - 10

6. The Choose Items to Install screen is next. I am going to stick with the default, as adding extensions that you don’t need increases your vulnerability profile.

If you have need of an additional Extension just open up the drop down and choose it, then click Next.

IIS 7: Install FastCGI and PHP on Server 2008 - 11

7. Here comes the big moment! Click Install and watch the magic happen.

IIS 7: Install FastCGI and PHP on Server 2008 - 12

8. You should see the Setup Completion screen now. Go ahead and click Finish.

IIS 7: Install FastCGI and PHP on Server 2008 - 13

9. Ok, now we will have to make a few modifications to the way PHP handles itself so we are going to modify the php.ini file.

First navigate to the place you installed PHP and open php.ini in notepad.

IIS 7: Install FastCGI and PHP on Server 2008 - 14

10. First let’s modify fastcgi.impersonate and set it to 1. Remember you are going to have to uncomment these first and then change the value, and also CTRL+F is your friend!

IIS 7: Install FastCGI and PHP on Server 2008 - 15

11. Now find cgi.fix_pathinfo and set it to 1 also, remember to uncomment by removing ;

IIS 7: Install FastCGI and PHP on Server 2008 - 16

12. Next up is cgi.force_redirect and we are going to set this to 0, and uncomment.

IIS 7: Install FastCGI and PHP on Server 2008 - 17

13. Then let’s set open_basedir to the root level of our website content directory, which I will use the default C:\inetpub

IIS 7: Install FastCGI and PHP on Server 2008 - 18

14. Now save your changes to php.ini

IIS 7: Install FastCGI and PHP on Server 2008 - 19

That’s it! Let’s go ahead and test the install, by going to a command prompt and doing the following:

1. Open a command prompt.

2. Navigate to the directory you installed PHP to.

3. Type in: PHP –info and you should see a lot of scrolling and information. This means PHP is good to go.

Below is the start of the command and output, then the second picture is the last thing that will be shown.

IIS 7: Install FastCGI and PHP on Server 2008 - 20

IIS 7: Install FastCGI and PHP on Server 2008 - 21

You have now properly installed and tested PHP on the server. Now we have to configure IIS 7 to use PHP through FastCGI.

How to Configure IIS7 to use PHP

IIS7 can be configured to handle PHP mappings at server or site levels, but for this example we are going to set the configuration at the server level. This just basically tells the server how to handle files with .php type extensions.

1. Open IIS Manager and select the server in the left pane and then click on Handler Mappings in the center pane.

IIS 7: Install FastCGI and PHP on Server 2008 - 22

2. In the right Action pane select Add Module Mapping…

IIS 7: Install FastCGI and PHP on Server 2008 - 23

3. Fill out the following information and click OK:

Request Path: *.php
Module: FastCgiModule
Executable: {path to your PHP install}\php-cgi.exe
Name: Whatever you want

IIS 7: Install FastCGI and PHP on Server 2008 - 24

4. You will get a popup asking if you want to create a FastCGI application, go ahead and click Yes.

IIS 7: Install FastCGI and PHP on Server 2008 - 25

5. You will now see your enabled handler in the list.

IIS 7: Install FastCGI and PHP on Server 2008 - 26

You have now successfully setup your IIS7 web server to handle PHP files via FastCgi. But don’t take my word for it, let’s go ahead and run a test.

1. Navigate to the default site directory at C:\inetpub\wwwroot

2. Create a file called info.php and place the following in the file:

<?php phpinfo(); ?>

3. Open your browser and point it at http://localhost/info.php and you should see a PHP information page similar to this:

IIS 7: Install FastCGI and PHP on Server 2008 - 27

This shows a successful handling of PHP files by IIS7. You have now configured your server to run PHP via FastCGI on IIS7.

My next article in this series will talk about installing some of the more popular databases and applications that can use PHP. If you have any requests feel free to leave a comment.

Want to prepare yourself for changing technology? Check out our Windows Server 2012 70-410 Training, and sign up for a 3-day free trial to access all of our courses!

About the Author

(MCTS, MCP, A+) has been working in the IT field since leaving the U.S. Army in 1996.  Working his way up from printer hardware repair to running a corporate datacenter for a multinational corporation, Dave has seen many environments throughout the years. Focusing on web sites and search engine optimization the last few years, with the release of Server 2008 it has renewed his passion for the Wintel platform and server technologies. David also runs Windows-Server-Training.com where he posts free videos and walk-throughs for a variety of server technologies. David currently works as a freelance technical consultant and writer for a variety of companies in the Chicago area.

Author's Website: http://www.DaveLawlor.com


Discussion