How to use FastCGI to Host PHP Applications on IIS 7

The FastCGI component in IIS allows popular app structures that support the FastCGI system to be hosted on the IIS Web server and help them to perform better and become reliable.

FastCGI offers a high-functionality option to the widely utilized Common Gateway Interface (CGI), which is a typical way to interface with external apps with Web servers that have been among IIS features supported started from the first time it was released.

CGI programs are files that are released by the Web server for the query to process and create non-stable responses that are returned to the user.

Given that a lot of these structures do not support multiple thread execution, CGI allows them to execute unfailingly on IIS by only process one request at a time.

Regrettably, it offers poor performance as a result of the high cost of setting and shutting down a procedure for every query sent.

FastCGI manages the functionality problems that are commonly found in CGI by offering a mechanism to reprocess one procedure repeatedly for a lot of queries.

Besides, FastCGI assists to sustain support with non-thread-safe libraries by offering a pool of re-utilizable procedures and making sure that each one of the procedures manages just a single request each time.

This article explains how you can set up the FastCGI element and PHP to host PHP apps on IIS 7 and above. You will learn how to install and make use of the FastCGI module on Windows Server 2008 and Windows Vista SP1. SP1 is needed on Windows Vista.

Step 1: Enable FastCGI Support in IIS Windows Server 2008

To do this, Open Server Manager, navigate to Roles and from there look for Insert Role Services. On Select Role Services page, pick the CGI tick box. CGI and FastCGI services will be enabled.

How to use FastCGI to Host PHP Applications on IIS 7

Open Control Panel -> Programs & Features -> Turn on/off the Windows features. In the Windows Features screen, choose the CGI tick box. CGI and FastCGI services will be enabled.

How to use FastCGI to Host PHP Applications on IIS 7

ESSENTIAL: Set up Update for FastCGI Module

Update for IIS FastCGI module mends some identified compatibility problems with famous PHP apps. Install update from any of the locations below:

  • Update for Windows Server 2008
  • Update for Windows Server 2008 x64 Edition
  • Update for Windows Server 2008 for Itanium-based Systems
  • Update for Windows Vista SP1
  • Update for Windows Vista SP1 for x64 based Systems

Step 2: Setup Administration Pack for IIS

Please Note That This one is non-compulsory. IIS Administration Pack has a suitable user interface for setting up the settings for FastCGI. Administration Pack installation can be done from the following locations:

  • Administration Pack for IIS 7 and Above – x86
  • Administration Pack for IIS 7 and Above – x64

Step 3: Install and Configure PHP

Using unthread secure PHP build with IIS FastCGI is better since it gives noteworthy performance gains more than the normal structure by omitting all thread-safety tests, which are unnecessary, given that FastCGI guarantees a single threaded implementation setting.

To set up PHP:

STEP A: Download latest unthread safe zip package with binaries of PHP: http://www.php.net/downloads.php.

STEP B: Unload the files on any directory you like (for example C:PHP). Change php.ini-recommended file name to php.ini.

EP C: Open php.ini file. Uncomment then change the settings as below:

  • Put fastcgi.impersonate = 1. FastCGI beneath IIS backs the capacity to imitate the calling customer’s security tokens. This enables IIS describe the safety framework that the query runs under.
  • Put cgi.fix_pathinfo=1. Cgi.fix_pathinfo gives *real* PATH_INFO/PATH_TRANSLATED support to CGI. Formerly, PHP performance was meant to set PATH_TRANSLATED to SCRIPT_FILENAME, and not to define PATH_INFO. For further information on PATH_INFO, check the cgi specs. Putting this value to 1 will make PHP CGI to mend its paths to adhere to the specs.
  • Put cgi.force_redirect = 0.
  • Put open_basedir to indicate the folder where Web site content is located.
  • Put extension_dir to indicate the place where PHP extensions are situated. Normally, PHP 5.2.X value would have been put at extension_dir = "./ext"
  • Necessary PHP extension should be enabled  by un-commenting matching lines, for instance:
extension=php_mssql.dll
extension=php_mysql.dll

Prompt a command, then run the command below to confirm PHP installation was successful:

consoleCopy

C:PHP>php -info

Once PHP was installed properly and every of its needs are present on the device, the existing PHP set up information will be output by this command.

Step 4: Set up IIS to Operate PHP Queries

For Internet Information Service to host PHP apps, it is a necessity to include a handler mapping which notifies IIS to forward every PHP-specific queries to the PHP application structure by making use of FastCGI protocol.

Set up IIS to Handle PHP Queries by Making Use of IIS Manager

STEP A: Launch IIS Manager. Double-click on Handler Mappings at server level.

How to use FastCGI to Host PHP Applications on IIS 7

STEP B: In Actions window, tap on Add Module Mapping. In new window, give configuration settings as below:

  • Request path: *.php
  • Module: FastCgiModule
  • Executable: "C:[Path to your PHP installation]php-cgi.exe"
  • Name: PHP via FastCGI
  • STEP C: Tap on OK.

How to use FastCGI to Host PHP Applications on IIS 7

STEP D: In Add Module Mapping verification window that says if you would like to make a FastCGI app for the executable, click on Yes.

How to use FastCGI to Host PHP Applications on IIS 7

STEP E: Check that handler mapping is working properly by generating a phpinfo.php file

in the C:inetpubwwwroot folder with the subsequent code:

XMLCopy

<?php phpinfo(); ?>

STEP F: Launch the browser and go to http://localhost/phpinfo.php. As long as all was configured properly, you should see the regular PHP page with information.

How to use FastCGI to Host PHP Applications on IIS 7

Take Note

If FastCgiModuledoesnot appear in the Module’ list, it is either the module is not registered or enabled. To test if FastCGI module is registered/enabled, open IIS set up file to be found at %windir%windowssystem32configapplicationHost.configand make sure the line below is there in the <globalModules>section:

XMLCopy

<add name="FastCgiModule" image="%windir%System32inetsrviisfcgi.dll" />
Also in that file, see that FastCGI module is included to <modules> section:
XMLCopy
<add name="FastCgiModule" />

STEP 5: Set Up IIS to Operate PHP Queries By Making Use of Command Line

Then again, you can accomplish the above steps by making use of command line instrument A ppCmd.

STEP A: Create FastCGI application procedure pool by entering the command below:

consoleCopy

C:>%windir%system32inetsrvappcmd set config /section:system.webServer/fastCGI /+[fullPath='c:{php_folder}php-cgi.exe']

STEP B: Create handler mapping by entering the command below:

consoleCopy

C:>%windir%system32inetsrvappcmd set config /section:system.webServer/handlers /+[name='PHP_via_FastCGI',path='*.php',verb='*',modules='FastCgiModule',scriptProcessor='c:{php_folder}php-cgi.exe',resourceType='Unspecified']

Conclusion

FastCGI deals with performance matters that are intrinsic in CGI by offering to a device the ability to reuse a single process repeatedly for countless requests. Furthermore, FastCGI retains compatibility with non-thread-protected libraries by giving a pool of recyclable processes and making sure that every process deals with only one request at a time. If you use PHP version 4.X, you may use php.exe rather than php-cgi.exe.

Check out these top 3 Best web hosting services

Was this article helpful?