Install PHP in IIS 7 As FastCgi Module
Install PHP in IIS 7 As FastCgi Module
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.
To enable FastCGI support on Windows Server 2008 and Windows Server 2008 R2:
1. In the Windows Start Menu choose "Run:", type "CompMgmtLauncher" and click "Ok"; 2. If the "Web Server (IIS)" role is not present under the "Roles" node, then add it by clicking "Add Roles"; 3. If the "Web Server (IIS)" role is present, then click "Add Role Services" and then enable the "CGI" checkbox under "Application Development" group; 4. Click "Next" and then "Install" and wait for the installation to complete.
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: 1. In the Windows Start Menu choose "Run:", type "inetmgr" and click "Ok"; 2. In the IIS Manager user interface select the server node in the "Connections" tree view; 3. In the "Features View" page open the "Handler Mappings" feature;
4. In the "Actions" pane click "Add Module Mapping..."; 5. In the "Add Module Mapping" dialog enter the following: o Request path: *.php o Module: FastCgiModule o Executable: C:\[Path to PHP installation]\php-cgi.exe o Name: PHP_via_FastCGI 6. Click "Request Restrictions" button and then configure the mapping to invoke handler only if request is mapped to a file or a folder; 7. Click OK on all the dialogs to save the configuration.
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 phpcgi.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 phpcgi.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: 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.
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)
%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