How To Add A FastCGI Environment Variable For PHP

How To Add A FastCGI Environment Variable For PHP

This article discusses all the steps you need to add a FastCGI environment variable for PHP in IIS web server.

The steps below would work only if you ensure that you have installed in your device after downloading the binaries which will conduct the execution of the file path or the extension of the file name that you have specified.

The implementation of the PHP we have used in the example below is as specified in the,” www.’” platform.

Step 1:
Open Internet Information Services (IIS) Manager

For those who are making use of either the 2012 Windows Server or the 2012 R2 Windows Server, then you should select the Server Manager option you see within the taskbar, click on the tools option which appears and choose the option tagged “Internet

Information Services (IIS) Manager

For the users of Windows 8.1 or the Windows 8, press the Windows key down, click on the letter X, and then select the Control Panel option you see. Select the Administrative Tools, and then click twice on the Internet Information Services (IIS) Manager.

For those making use of the 2008 R2 Windows Server or the 2008 Windows Server, click on the Start feature you see on the taskbar, hover your mouse over the Administrative Tools option to bring forth some options. Then select the Internet

Information Services (IIS) Manager.

For the users of Windows 7 or the Windows Vista, follow the Start feature you see on the taskbar and select the Control Panel option. Click twice on the Administrative Tools, and then click twice again on the Internet Information Services (IIS) Manager.

Step 2:
Choose Server Name

In the pane tagged “Connections”, choose the name of the server you wish to configure the settings of the FastCGI to:

Step 3:
Choose Setting

Then in the panel tagged “Home”, click twice on the FastCGI Settings option.

How To Add A FastCGI Environment Variable For PHP

Step 4:
Edit PHP

You should highlight the PHP application found on the panel of the FastCGI Settings and then the click on the“Edit” option under the panel for “Action.

How To Add A FastCGI Environment Variable For PHP

Step 5:
Open Environment Variables

In the dialog box for the Edit FastCGI Application, click on the ellipsis which stands next to the EnvironmentVariables in order to make the collection editor for the environment variables open.

How To Add A FastCGI Environment Variable For PHP

Step 6:
Click On


In the dialog box which appears for the EnvironmentVariables Collection Editor, click on the “add” feature.

How To Add A FastCGI Environment Variable For PHP

Step 7:
Enter Information

The information “PHP_FCGI_MAX_REQUESTS” should be entered to represent the name, and then for the Value, “10000” should be entered.

How To Add A FastCGI Environment Variable For PHP

Step 8:
Close Application

As soon as you’ve done that, click on the “OK” option to close the dialog box of the Add FastCGI Application.


The element of the FastCGI can be configured at the level of the server in the file of the”ApplicationHost.config”, or at the level of the site, the level of the application or then in a “Web.config” file at the level of the directory.

Child Elements

Application:It is an element which is optional and adds to the set of definitions of the FastCGI process pool, a certain definition of a FastCGI process pool.

Configuration Sample

The configuration sample below, incoporates FastCGI application for PHP, sets the instanceMaxRequests attribute to “10000,” and sets the PHP_FCGI_MAX_REQUESTS environment variable to “10000.

<application fullPath="C:PHPphp-cgi.exe"
value="10000" />

Note that the environment variable of the PHP_FCGI_MAX_REQUESTS used for a PHP should be a number either equal to or less than the value which has been specified by the FastCGI <application> element’s attribute “instanceMaxRequests” .

Also, each of the sample adds a wide FastCGI handler mapping used for PHP type files to IIS. It also shows the complete path to the FastCGI file which is executable.

<location path=""overrideMode="Allow">
<add name="PHP-FastCGI"
requireAccess="Script" />

You should note that you can configure the settings of the FastCGI per-site by using a FastCGI application which has been formatted specially and also by using mappings of handlers which are differentiated from others by matching the “arguments” and “fullPath” attributes for an element of an <application> alongside the corresponding attribute, “scriptProcessor”for the process of the FastCGI in the <handlers> mapping.

The attribute of the scriptProcessor in the <handlers> mapping for the process of the FastCGI should be merged to the arguments and fullPath attributes’ settings for an element of an<application> and then separated by the use of a pipe character “ | ” in order to make these mappings.

The combination stands as a unique type of key for every one of the FastCGI application. An example is shown below:

<application fullPath="C:PHPphp-cgi.exe"
arguments="-d open_basedir=C:WebsitesWebsite1" />
<application fullPath="C:PHPphp-cgi.exe"
arguments="-d open_basedir=C:WebsitesWebsite2" />
<handlers accessPolicy="Read, Script">
<add name="PHP via FastCGI 1"
scriptProcessor="C:PHPphp-cgi.exe|-d open_basedir=C:WebsitesWebsite1"
requireAccess="Script" />
<add name="PHP via FastCGI 2"
scriptProcessor="C:PHPphp-cgi.exe|-d open_basedir=C:WebsitesWebsite2"
requireAccess="Script" />

Sample Code

The sample below, used in configuring for a PHP, a FastCGI application, setting to a “10000” attribute, the instanceMaxRequestsand also setting to “10000”, the environment variable for the PHP_FCGI_MAX_REQUESTS. Also, each of the sample adds a wide FastCGI handler mapping used for PHP type files to IIS. It also shows the complete path to the FastCGI file which is executable.


appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='C:PHPphp-cgi.exe',arguments='',maxInstances='4',idleTimeout='300',activityTimeout='30',requestTimeout='90',instanceMaxRequests='10000',protocol='NamedPipe',flushNamedPipe='False']" /commit:apphost
appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='C:PHPphp-cgi.exe'].environmentVariables.[name='PHP_FCGI_MAX_REQUESTS',value='10000']" /commit:apphost
appcmd.exe set config -section:system.webServer/handlers /+"[name='PHP-FastCGI',path='*.php',verb='GET,HEAD,POST',modules='FastCgiModule',scriptProcessor='C:PHPphp-cgi.exe',resourceType='Either',requireAccess='Script']" /commit:apphost

You should note that when you are making use of the AppCmd.exe in configuring these listed settings, you must ensure the commit parameter is set to “apphost”. Doing this links these settings for configurations to the correct location part in the ApplicationHost.config file.

The C#

using System;
using (ServerManagerserverManager = newServerManager())
             Configuration config = serverManager.GetApplicationHostConfiguration();
ConfigurationSectionfastCgiSection = config.GetSection("system.webServer/fastCgi");
ConfigurationElementCollectionfastCgiCollection = fastCgiSection.GetCollection();
ConfigurationElementapplicationElement = fastCgiCollection.CreateElement("application");
applicationElement["fullPath"] = @"C:PHPphp-cgi.exe";
applicationElement["arguments"] = @"";
applicationElement["maxInstances"] = 4;
applicationElement["idleTimeout"] = 300;
applicationElement["activityTimeout"] = 30;
applicationElement["requestTimeout"] = 90;
applicationElement["instanceMaxRequests"] = 10000;
applicationElement["protocol"] = @"NamedPipe";
applicationElement["flushNamedPipe"] = false;
ConfigurationElementCollectionenvironmentVariablesCollection = applicationElement.GetCollection("environmentVariables");
ConfigurationElementenvironmentVariableElement = environmentVariablesCollection.CreateElement("environmentVariable");
environmentVariableElement["name"] = @"PHP_FCGI_MAX_REQUESTS";
environmentVariableElement["value"] = @"10000";
ConfigurationSectionhandlersSection = config.GetSection("system.webServer/handlers");
ConfigurationElementCollectionhandlersCollection = handlersSection.GetCollection();
ConfigurationElementaddElement = handlersCollection.CreateElement("add");
addElement["name"] = @"PHP-FastCGI";
addElement["path"] = @"*.php";
addElement["verb"] = @"GET,HEAD,POST";
addElement["modules"] = @"FastCgiModule";
addElement["scriptProcessor"] = @"C:PHPphp-cgi.exe";
addElement["resourceType"] = @"Either";
addElement["requireAccess"] = @"Script";
handlersCollection.AddAt(0, addElement);


Imports System
Module Sample
Sub Main()
DimserverManagerAsServerManager = NewServerManager
DimconfigAs Configuration = serverManager.GetApplicationHostConfiguration
DimfastCgiSectionAsConfigurationSection = config.GetSection("system.webServer/fastCgi")
DimfastCgiCollectionAsConfigurationElementCollection = fastCgiSection.GetCollection
DimapplicationElementAsConfigurationElement = fastCgiCollection.CreateElement("application")
applicationElement("fullPath") = "C:PHPphp-cgi.exe"
applicationElement("arguments") = ""
applicationElement("maxInstances") = 4
applicationElement("idleTimeout") = 300
applicationElement("activityTimeout") = 30
applicationElement("requestTimeout") = 90
applicationElement("instanceMaxRequests") = 10000
applicationElement("protocol") = "NamedPipe"
applicationElement("flushNamedPipe") = False
DimenvironmentVariablesCollectionAsConfigurationElementCollection = applicationElement.GetCollection("environmentVariables")
DimenvironmentVariableElementAsConfigurationElement = environmentVariablesCollection.CreateElement("environmentVariable")
environmentVariableElement("name") = "PHP_FCGI_MAX_REQUESTS"
environmentVariableElement("value") = "10000"
DimhandlersSectionAsConfigurationSection = config.GetSection("system.webServer/handlers")
DimhandlersCollectionAsConfigurationElementCollection = handlersSection.GetCollection
DimaddElementAsConfigurationElement = handlersCollection.CreateElement("add")
addElement("name") = "PHP-FastCGI"
addElement("path") = "*.php"
addElement("verb") = "GET,HEAD,POST"
addElement("modules") = "FastCgiModule"
addElement("scriptProcessor") = "C:PHPphp-cgi.exe"
addElement("resourceType") = "Either"
addElement("requireAccess") = "Script"
handlersCollection.AddAt(0, addElement)

The JavaScript

varadminManager = newActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
varfastCgiSection = adminManager.GetAdminSection("system.webServer/fastCgi", "MACHINE/WEBROOT/APPHOST");
varfastCgiCollection = fastCgiSection.Collection;
varapplicationElement = fastCgiCollection.CreateNewElement("application");
applicationElement.Properties.Item("fullPath").Value = "C:\PHP\php-cgi.exe";
applicationElement.Properties.Item("arguments").Value = "";
applicationElement.Properties.Item("maxInstances").Value = 4;
applicationElement.Properties.Item("idleTimeout").Value = 300;
applicationElement.Properties.Item("activityTimeout").Value = 30;
applicationElement.Properties.Item("requestTimeout").Value = 90;
applicationElement.Properties.Item("instanceMaxRequests").Value = 10000;
applicationElement.Properties.Item("protocol").Value = "NamedPipe";
applicationElement.Properties.Item("queueLength").Value = 1000;
applicationElement.Properties.Item("flushNamedPipe").Value = false;
applicationElement.Properties.Item("rapidFailsPerMinute").Value = 10;
varenvironmentVariablesCollection = applicationElement.ChildElements.Item("environmentVariables").Collection;
varenvironmentVariableElement = environmentVariablesCollection.CreateNewElement("environmentVariable");
environmentVariableElement.Properties.Item("name").Value = "PHP_FCGI_MAX_REQUESTS";
environmentVariableElement.Properties.Item("value").Value = "10000";
varhandlersSection = adminManager.GetAdminSection("system.webServer/handlers", "MACHINE/WEBROOT/APPHOST");
varhandlersCollection = handlersSection.Collection;
varaddElement = handlersCollection.CreateNewElement("add");
addElement.Properties.Item("name").Value = "PHP-FastCGI";
addElement.Properties.Item("path").Value = "*.php";
addElement.Properties.Item("verb").Value = "GET,HEAD,POST";
addElement.Properties.Item("modules").Value = "FastCgiModule";
addElement.Properties.Item("scriptProcessor").Value = "C:\PHP\php-cgi.exe";
addElement.Properties.Item("resourceType").Value = "Either";
addElement.Properties.Item("requireAccess").Value = "Script";
handlersCollection.AddElement(addElement, 0);

The VBScript

SetadminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
SetfastCgiSection = adminManager.GetAdminSection("system.webServer/fastCgi", "MACHINE/WEBROOT/APPHOST")
SetfastCgiCollection = fastCgiSection.Collection
SetapplicationElement = fastCgiCollection.CreateNewElement("application")
applicationElement.Properties.Item("fullPath").Value = "C:PHPphp-cgi.exe"
applicationElement.Properties.Item("arguments").Value = ""
applicationElement.Properties.Item("maxInstances").Value = 4
applicationElement.Properties.Item("idleTimeout").Value = 300
applicationElement.Properties.Item("activityTimeout").Value = 30
applicationElement.Properties.Item("requestTimeout").Value = 90
applicationElement.Properties.Item("instanceMaxRequests").Value = 10000
applicationElement.Properties.Item("protocol").Value = "NamedPipe"
applicationElement.Properties.Item("queueLength").Value = 1000
applicationElement.Properties.Item("flushNamedPipe").Value = false
applicationElement.Properties.Item("rapidFailsPerMinute").Value = 10
SetenvironmentVariablesCollection = applicationElement.ChildElements.Item("environmentVariables").Collection
SetenvironmentVariableElement = environmentVariablesCollection.CreateNewElement("environmentVariable")
environmentVariableElement.Properties.Item("name").Value = "PHP_FCGI_MAX_REQUESTS"
environmentVariableElement.Properties.Item("value").Value = "10000"
SethandlersSection = adminManager.GetAdminSection("system.webServer/handlers", "MACHINE/WEBROOT/APPHOST")
SethandlersCollection = handlersSection.Collection
SetaddElement = handlersCollection.CreateNewElement("add")
addElement.Properties.Item("name").Value = "PHP-FastCGI"
addElement.Properties.Item("path").Value = "*.php"
addElement.Properties.Item("verb").Value = "GET,HEAD,POST"
addElement.Properties.Item("modules").Value = "FastCgiModule"
addElement.Properties.Item("scriptProcessor").Value = "C:PHPphp-cgi.exe"
addElement.Properties.Item("resourceType").Value = "Either"
addElement.Properties.Item("requireAccess").Value = "Script"
CallhandlersCollection.AddElement(addElement, 0)

Check out these top 3 Best web hosting services.

$2.99 /mo
Starting price
Visit Hostinger
Rating based on expert review
  • User Friendly
  • Support
  • Features
  • Reliability
  • Pricing
$1.00 /mo
Starting price
Rating based on expert review
  • User Friendly
  • Support
  • Features
  • Reliability
  • Pricing
$2.90 /mo
Starting price
Visit Ultahost
Rating based on expert review
  • User Friendly
  • Support
  • Features
  • Reliability
  • Pricing

How to Install PHP with FastCGI Extension on IIS 7 / IIS 8 Server

This guide describes how to install PHP with FastCGI on IIS7 / IIS8 server. Ac
4 min read
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert

How to Install MySQL on a Windows Web Server Running Apache

This tutorial will show you how to install the MySQL database on a Windows serve
3 min read
Michael Levanduski
Michael Levanduski
Expert Hosting Writer & Tester

How to Install OpenCart on an Ubuntu 18.04 Server or VPS with Apache, MariaDB and PHP 7

In this how-to, you'll learn how to install OpenCart, an open source shopping ca
3 min read
Angela Olaru
Angela Olaru
Senior Writer & Hosting Expert

How to Configure PHP Versions and Options on cPanel

This guide will show new webmasters about switching to different PHP versions an
2 min read
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top