applicationhost.config 位於:
%USERPROFILE%\Documents\IISExpress\config\applicationhost.config(優先)C:\Program Files\IIS Express\applicationhost.config<defaultDocument><defaultDocument enabled="true">
<files>
<add value="Default.htm" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="index.html" />
<add value="iisstart.htm" />
<add value="default.aspx" />
<add value="index.php" /> <!-- 關鍵:添加 PHP 入口 -->
</files>
</defaultDocument>
<fastCgi><fastCgi>
<application
fullPath="C:\php\php-cgi.exe"
monitorChangesTo="php.ini"
activityTimeout="600"
requestTimeout="600"
instanceMaxRequests="10000">
<environmentVariables>
<environmentVariable name="PHP_FCGI_MAX_REQUESTS" value="10000" />
<environmentVariable name="PHPRC" value="C:\Program Files (x86)\IIS Express\PHP\v5.4" /> <!-- PHP.ini 目錄 -->
</environmentVariables>
</application>
</fastCgi>
注意: 路徑請替換為實際 PHP 安裝路徑,建議使用短路徑無空格(如 C:\php)。
<handlers><handlers accessPolicy="Read, Script">
<!-- 必須放在第一位,避免被 StaticFile/其他處理程序搶先 -->
<add name="PHP_FastCGI"
path="*.php"
verb="GET,HEAD,POST"
modules="FastCgiModule"
scriptProcessor="C:\php\php-cgi.exe"
resourceType="Either"
requireAccess="Script" />
<!-- 其他 handlers ... -->
</handlers>
<site><site name="MySite" id="1">
<application path="/">
<virtualDirectory path="/" physicalPath="D:\wwwroot\mysite" />
</application>
<bindings>
<binding protocol="http" bindingInformation=":8080:" /> <!-- 端口 8080,避免衝突 -->
</bindings>
</site>
或使用命令行快速建站:
appcmd.exe add site /name:"MySite" /physicalPath:"D:\wwwroot\mysite" /bindings:http/*:8080:
放置於 WordPress 根目錄:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="WordPress" patternSyntax="Wildcard">
<match url="*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
<urlCompression doStaticCompression="true" doDynamicCompression="true" />
<defaultDocument>
<files>
<add value="index.php" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
cd "C:\Program Files\IIS Express"iisexpress.exe /site:"MySite"IISExpress.exe(會加載所有已配置站點)。https://localhost:8080 或 https://服務器IP:8080。| 指標 | Apache 2.2 (Prefork) + mod_php | IIS 7.5 Express + FastCGI |
|---|---|---|
| 內存佔用 (空閒) | ~80-120 MB | ~15-30 MB |
| PHP 進程模型 | 嵌入 Apache 進程,每請求一線程 | 獨立 php-cgi.exe 池,進程復用 |
| 靜態文件處理 | Apache 內部 | IIS 內核緩存 + 靜態壓縮 |
| Rewrite 支持 | 需 mod_rewrite | 內建 URL Rewrite Module |
| Windows 整合 | 一般 | 原生 (IUSR、ACL、ETW 追蹤) |
NSSM 封裝為服務。PHPRC 環境變量必須指向包含 php.ini 的目錄,否則 PHP 會讀取系統目錄下的錯誤配置。requestTimeout、activityTimeout 及 PHP max_execution_time、upload_max_filesize。