Microsoft Iis 7.0 and Later: Enabling Fastcgi Support in Iis

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

[edit] Last updated: Fri, 19 Apr 2013

Microsoft IIS 7.0 and later


This section contains instructions for manually setting up Internet Information Services (IIS) 7.0 and
later to work with PHP on Microsoft Windows Vista SP1, Windows 7, Windows Server 2008 and Windows Server 2008 R2.
For instructions on setting up IIS 5.1 and IIS 6.0 on Windows XP and Windows Server 2003 refer to Microsoft IIS 5.1 and IIS
6.0.
Enabling FastCGI support in IIS
FastCGI module is disabled in default installation of IIS. The steps to enable it differ based on the version of Windows being
used.
To enable FastCGI support on Windows Vista SP1 and Windows 7:
In the Windows Start Menu choose "Run:", type "optionalfeatures.exe" and click "Ok"; 1.
In the "Windows Features" dialog expand "Internet Information Services", "World Wide Web Services", "Application
Development Features" and then enable the "CGI" checkbox;
2.
Click OK and wait until the installation is complete. 3.
To enable FastCGI support on Windows Server 2008 and Windows Server 2008 R2:
In the Windows Start Menu choose "Run:", type "CompMgmtLauncher" and click "Ok"; 1.
If the "Web Server (IIS)" role is not present under the "Roles" node, then add it by clicking "Add Roles"; 2.
PHP: Microsoft IIS 7.0 and later - Manual http://php.net/manual/en/install.windows.iis7.php
1 de 7 23/04/13 21:41
If the "Web Server (IIS)" role is present, then click "Add Role Services" and then enable the "CGI" checkbox under
"Application Development" group;
3.
Click "Next" and then "Install" and wait for the installation to complete. 4.
Configuring IIS to process PHP requests
Download and install PHP in accordance to the instructions described in manual installation steps
Note:
Non-thread-safe build of PHP is recommended when using IIS. The non-thread-safe builds are available at PHP for
Windows: Binaries and Sources Releases.
Configure the CGI- and FastCGI-specific settings in php.ini file as shown below:
Example #1 CGI and FastCGI settings in php.ini
fastcgi.impersonate = 1
fastcgi.logging = 0
cgi.fix_pathinfo=1
cgi.force_redirect = 0
Configure IIS handler mapping for PHP by using either IIS Manager user interface or a command line tool.
Using IIS Manager user interface to create a handler mapping for PHP
Follow these steps to create an IIS handler mapping for PHP in IIS Manager user interface:
PHP: Microsoft IIS 7.0 and later - Manual http://php.net/manual/en/install.windows.iis7.php
2 de 7 23/04/13 21:41
In the Windows Start Menu choose "Run:", type "inetmgr" and click "Ok"; 1.
In the IIS Manager user interface select the server node in the "Connections" tree view; 2.
In the "Features View" page open the "Handler Mappings" feature; 3.
In the "Actions" pane click "Add Module Mapping..."; 4.
In the "Add Module Mapping" dialog enter the following:
Request path: *.php
Module: FastCgiModule
Executable: C:\[Path to PHP installation]\php-cgi.exe
Name: PHP_via_FastCGI
5.
Click "Request Restrictions" button and then configure the mapping to invoke handler only if request is mapped to a file
or a folder;
6.
Click OK on all the dialogs to save the configuration. 7.
PHP: Microsoft IIS 7.0 and later - Manual http://php.net/manual/en/install.windows.iis7.php
3 de 7 23/04/13 21:41
Using command line tool to create a handler mapping for PHP
Use the command shown below to create an IIS FastCGI process pool which will use php-cgi.exe executable for processing
PHP requests. Replace the value of the fullPath parameter with the absolute file path to the php-cgi.exe file.
Example #2 Creating IIS FastCGI process pool
%windir%\system32\inetsrv\appcmd set config /section:system.webServer/fastCGI ^
/+[fullPath='c:\PHP\php-cgi.exe']
Configure IIS to handle PHP specific requests by running the command shown below. Replace the value of the
scriptProcessor parameter with the absolute file path to the php-cgi.exe file.
Example #3 Creating handler mapping for PHP requests
%windir%\system32\inetsrv\appcmd set config /section:system.webServer/handlers ^
/+[name='PHP_via_FastCGI', path='*.php',verb='*',modules='FastCgiModule',^
scriptProcessor='c:\PHP\php-cgi.exe',resourceType='Either']
This command creates an IIS handler mapping for *.php file extension, which will result in all URLs that end with .php being
handled by FastCGI module.
Note:
PHP: Microsoft IIS 7.0 and later - Manual http://php.net/manual/en/install.windows.iis7.php
4 de 7 23/04/13 21:41
At this point the required installation and configuration steps are completed. The remaining instructions below are
optional but highly recommended for achieving optimal functionality and performance of PHP on IIS.
Impersonation and file system access
It is recommended to enable FastCGI impersonation in PHP when using IIS. This is controlled by the fastcgi.impersonate
directive in php.ini file. When impersonation is enabled, PHP will perform all the file system operations on behalf of the user
account that has been determined by IIS authentication. This ensures that even if the same PHP process is shared across
different IIS web sites, the PHP scripts in those web sites will not be able to access each other's files as long as different user
accounts are used for IIS authentication on each web site.
For example IIS 7, in its default configuration, has anonymous authentication enabled with built-in user account IUSR used as
a default identity. This means that in order for IIS to execute PHP scripts, it is necessary to grant IUSR account read
permission on those scripts. If PHP applications need to perform write operations on certain files or write files into some
folders then IUSR account should have write permission to those.
To determine what user account is used as an anonymous identity in IIS 7 use the following command. Replace the "Default
Web Site" with the name of IIS web site that you use. In the output XML configuration element look for the userName attribute.
Example #4 Determining the account used as IIS anonymous identity
%windir%\system32\inetsrv\appcmd.exe list config "Default Web Site" ^
/section:anonymousAuthentication
<system.webServer>
<security>
<authentication>
<anonymousAuthentication enabled="true" userName="IUSR" />
</authentication>
</security>
</system.webServer>
Note:
If userName attribute is not present in the anonymousAuthentication element, or is set to an empty string, then it means
that the application pool identity is used as an anonymous identity for that web site.
To modify the permissions settings on files and folders, use the Windows Explorer user interface or icacls command.
Example #5 Configuring file access permissions
icacls C:\inetpub\wwwroot\upload /grant IUSR:(OI)(CI)(M)
Set index.php as a default document in IIS
The IIS default documents are used for HTTP requests that do not specify a document name. With PHP applications,
index.php usually acts as a default document. To add index.php to the list of IIS default documents, use this command:
Example #6 Set index.php as a default document in IIS
%windir%\system32\inetsrv\appcmd.exe set config ^
-section:system.webServer/defaultDocument /+"files.[value='index.php']" ^
/commit:apphost
PHP: Microsoft IIS 7.0 and later - Manual http://php.net/manual/en/install.windows.iis7.php
5 de 7 23/04/13 21:41
1
10 months ago
FastCGI and PHP Recycling configuration
Configure IIS FastCGI settings for recycling of PHP processes by using the commands shown below. The FastCGI setting
instanceMaxRequests controls how many requests will be processed by a single php-cgi.exe process before IIS shuts it
down. The PHP environment variable PHP_FCGI_MAX_REQUESTS controls how many requests a single php-cgi.exe
process will handle before it recycles itself. Make sure that the value specified for FastCGI InstanceMaxRequests setting is
less than or equal to the value specified for PHP_FCGI_MAX_REQUESTS.
Example #7 Configuring FastCGI and PHP recycling
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi ^
/[fullPath='c:\php\php-cgi.exe'].instanceMaxRequests:10000
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi ^
/+"[fullPath='C:\{php_folder}\php-cgi.exe'].environmentVariables.^
[name='PHP_FCGI_MAX_REQUESTS',value='10000']"
FastCGI timeout settings
Increase the timeout settings for FastCGI if it is expected to have long running PHP scripts. The two settings that control
timeouts are activityTimeout and requestTimeout. Use the commands below to change the timeout settings. Make sure to
replace the value in the fullPath parameter to contain the absolute path to the php-cgi.exe file.
Example #8 Configuring FastCGI timeout settings
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi ^
/[fullPath='C:\php\php-cgi.exe',arguments=''].activityTimeout:"90" /commit:apphost
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi ^
/[fullPath='C:\php\php-cgi.exe',arguments=''].requestTimeout:"90" /commit:apphost
Changing the Location of php.ini file
PHP searches for php.ini file in several locations and it is possible to change the default locations of php.ini file by using
PHPRC environment variable. To instruct PHP to load the configuration file from a custom location run the command shown
below. The absolute path to the directory with php.ini file should be specified as a value of PHPRC environment variable.
Example #9 Changing the location of php.ini file
appcmd.exe set config -section:system.webServer/fastCgi ^
/+"[fullPath='C:\php\php.exe',arguments=''].environmentVariables.^
[name='PHPRC',value='C:\Some\Directory\']" /commit:apphost
User Contributed Notes Microsoft IIS 7.0 and later - [5 notes]
mfuhrman at enetarch dot net
When installing PHP in Windows 2008 Server R2, you might find that Windows IIS 7 returns
error code 500 when executing scripts. To resolve this do two things:
1) browse to the folder that contains the script with the error using CMD. Yes, this is
the command prompt.
Then execute the script using something like: "C:\Program Files\PHP\PHP5.4\php.exe"
[script-filename].php
PHP: Microsoft IIS 7.0 and later - Manual http://php.net/manual/en/install.windows.iis7.php
6 de 7 23/04/13 21:41
1
10 months ago
0
8 months ago
0
3 years ago
0
2 days ago
Note that the quotes ("") are needed for file paths with spaces.
This will return the results of the script and any errors you might have.
2) To have IIS 7 return the errors to your webbrowser, turn off error logging and turn on
display errors. And to make sure that all the errors are display, set error reporting to
ALL.
log_errors = Off
display_errors = On
error_reporting = E_ALL
NG
Example #9 fails unless I change "php.exe" to "php-cgi.exe" as follows:
appcmd.exe set config -section:system.webServer/fastCgi ^
/+"[fullPath='C:\php\php-cgi.exe',arguments=''].environmentVariables.^
[name='PHPRC',value='C:\PHP\']" /commit:apphost
stpetersn at hotmail dot com
For setting the time out above it took me forever to figure out the right combination for
double and single quotes (and no quotes) given I had spaces in the absolute path to my
php-cgi.exe file. Here is what worked in case you have/had the same problem:
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi ^
/[fullPath="'C:\Program Files (x86)\PHP\php-cgi.exe'"].activityTimeout:90 /commit:apphost
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi ^
/[fullPath="'C:\Program Files (x86)\PHP\php-cgi.exe'"].requestTimeout:90 /commit:apphost
Bruce Kirkpatrick
The default installation of Windows Vista, Windows 7 and Windows Server 2008 adds a line
to the Windows/System32/drivers/etc/hosts which causes network functions (database
connect functions too, like mysql_connect) to timeout when connecting to "localhost". To
resolve this problem, remove the entry from the hosts file:
::1 localhost
or connect using the IP address, 127.0.0.1 or another domain name.
This behavior change is due to IPv6 being enabled by default in Vista or other recent
Windows version.
Now you can use the x64 snapshot builds of 5.3 on these new windows platforms to run a
completely up to date 64-bit fastcgi configuration!
Roberto
If you are having trouble with large uploads timing-out, it may be an IIS setting called
"maxAllowedContentLength" under "Request Filtering" > "Edit Feature Settings...". It is
set to 30000000 (~30MB) by default.
Copyright 2001-2013 The PHP Group
All rights reserved.
PHP: Microsoft IIS 7.0 and later - Manual http://php.net/manual/en/install.windows.iis7.php
7 de 7 23/04/13 21:41

You might also like