18
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 i nstallation 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 i nstalled so let’s go with that. If you need help installing the web server you can read my arti cle 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.

1ere Etape IIS 7 Install FastCGI PHP on Server 2008

Embed Size (px)

Citation preview

8/9/2019 1ere Etape IIS 7 Install FastCGI PHP on Server 2008

http://slidepdf.com/reader/full/1ere-etape-iis-7-install-fastcgi-php-on-server-2008 1/18

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.

8/9/2019 1ere Etape IIS 7 Install FastCGI PHP on Server 2008

http://slidepdf.com/reader/full/1ere-etape-iis-7-install-fastcgi-php-on-server-2008 2/18

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

click Next.

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

8/9/2019 1ere Etape IIS 7 Install FastCGI PHP on Server 2008

http://slidepdf.com/reader/full/1ere-etape-iis-7-install-fastcgi-php-on-server-2008 3/18

 

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

click Close.

8/9/2019 1ere Etape IIS 7 Install FastCGI PHP on Server 2008

http://slidepdf.com/reader/full/1ere-etape-iis-7-install-fastcgi-php-on-server-2008 4/18

 

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

8/9/2019 1ere Etape IIS 7 Install FastCGI PHP on Server 2008

http://slidepdf.com/reader/full/1ere-etape-iis-7-install-fastcgi-php-on-server-2008 5/18

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.

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

8/9/2019 1ere Etape IIS 7 Install FastCGI PHP on Server 2008

http://slidepdf.com/reader/full/1ere-etape-iis-7-install-fastcgi-php-on-server-2008 6/18

 

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.

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.

8/9/2019 1ere Etape IIS 7 Install FastCGI PHP on Server 2008

http://slidepdf.com/reader/full/1ere-etape-iis-7-install-fastcgi-php-on-server-2008 7/18

 

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

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.

8/9/2019 1ere Etape IIS 7 Install FastCGI PHP on Server 2008

http://slidepdf.com/reader/full/1ere-etape-iis-7-install-fastcgi-php-on-server-2008 8/18

 

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

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

8/9/2019 1ere Etape IIS 7 Install FastCGI PHP on Server 2008

http://slidepdf.com/reader/full/1ere-etape-iis-7-install-fastcgi-php-on-server-2008 9/18

 

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.

8/9/2019 1ere Etape IIS 7 Install FastCGI PHP on Server 2008

http://slidepdf.com/reader/full/1ere-etape-iis-7-install-fastcgi-php-on-server-2008 10/18

 

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!

8/9/2019 1ere Etape IIS 7 Install FastCGI PHP on Server 2008

http://slidepdf.com/reader/full/1ere-etape-iis-7-install-fastcgi-php-on-server-2008 11/18

 

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

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

8/9/2019 1ere Etape IIS 7 Install FastCGI PHP on Server 2008

http://slidepdf.com/reader/full/1ere-etape-iis-7-install-fastcgi-php-on-server-2008 12/18

 

13. Then let’s set open_basedir to the root level of our website content directory, which I will

use the default C:\inetpub 

14. Now save your changes to php.ini 

8/9/2019 1ere Etape IIS 7 Install FastCGI PHP on Server 2008

http://slidepdf.com/reader/full/1ere-etape-iis-7-install-fastcgi-php-on-server-2008 13/18

 

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.

8/9/2019 1ere Etape IIS 7 Install FastCGI PHP on Server 2008

http://slidepdf.com/reader/full/1ere-etape-iis-7-install-fastcgi-php-on-server-2008 14/18

 

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.

8/9/2019 1ere Etape IIS 7 Install FastCGI PHP on Server 2008

http://slidepdf.com/reader/full/1ere-etape-iis-7-install-fastcgi-php-on-server-2008 15/18

 

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

8/9/2019 1ere Etape IIS 7 Install FastCGI PHP on Server 2008

http://slidepdf.com/reader/full/1ere-etape-iis-7-install-fastcgi-php-on-server-2008 16/18

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 

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

Yes.

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

8/9/2019 1ere Etape IIS 7 Install FastCGI PHP on Server 2008

http://slidepdf.com/reader/full/1ere-etape-iis-7-install-fastcgi-php-on-server-2008 17/18

 

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:

8/9/2019 1ere Etape IIS 7 Install FastCGI PHP on Server 2008

http://slidepdf.com/reader/full/1ere-etape-iis-7-install-fastcgi-php-on-server-2008 18/18

 

This shows a successful handling of PHP files by IIS7. You have now configured your server

to run PHP via FastCGI on IIS7.