2024 年日本 PHP 研討會

在 Windows 上使用 IIS 進行安裝

安裝 IIS

網際網路資訊服務 (IIS) 內建於 Windows 中。在 Windows Server 上,可以透過伺服器管理員新增 IIS 角色。需要包含 CGI 角色功能。在 Windows 桌面版上,必須透過控制台的「新增/移除程式」來新增 IIS。Microsoft 文件有 » 啟用 IIS 的詳細說明。開發時,也可以使用 » IIS/Express

注意使用 FastCGI 處理常式搭配 IIS 時,應安裝非執行緒安全 (NTS) 版本的 PHP。

使用 IIS 設定 PHP

在 IIS 管理員中,安裝 FastCGI 模組,並將 .php 的處理常式對應新增至 php-cgi.exe(不是 php.exe)的路徑。

可以使用 APPCMD 命令列工具來編寫 IIS 設定指令碼。

批次檔範例

範例 #1 設定 IIS 和 PHP 的命令列

@echo off

REM download .ZIP file of PHP build from http://windows.php.net/downloads/

REM path to directory into which PHP .ZIP file was decompressed (no trailing \)
set phppath=c:\php


REM Clear current PHP handlers
%windir%\system32\inetsrv\appcmd clear config /section:system.webServer/fastCGI
REM The following command will generate an error message if PHP is not installed. This can be ignored.
%windir%\system32\inetsrv\appcmd set config /section:system.webServer/handlers /-[name='PHP_via_FastCGI']

REM Set up the PHP handler
%windir%\system32\inetsrv\appcmd set config /section:system.webServer/fastCGI /+[fullPath='%phppath%\php-cgi.exe']
%windir%\system32\inetsrv\appcmd set config /section:system.webServer/handlers /+[name='PHP_via_FastCGI',path='*.php',verb='*',modules='FastCgiModule',scriptProcessor='%phppath%\php-cgi.exe',resourceType='Unspecified']
%windir%\system32\inetsrv\appcmd set config /section:system.webServer/handlers /accessPolicy:Read,Script

REM Configure FastCGI Variables
%windir%\system32\inetsrv\appcmd set config -section:system.webServer/fastCgi /[fullPath='%phppath%\php-cgi.exe'].instanceMaxRequests:10000
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='%phppath%\php-cgi.exe'].environmentVariables.[name='PHP_FCGI_MAX_REQUESTS',value='10000']"
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='%phppath%\php-cgi.exe'].environmentVariables.[name='PHPRC',value='%phppath%\php.ini']"
新增註記

使用者貢獻的註記

此頁面沒有使用者貢獻的註記。
To Top