如何使用IIS管理器部署运行Laravel?配置完成后出现异常求解决
IIS 部署 Laravel 修复方案
前置检查
- 确认IIS已安装URL重写模块,未安装的话先安装后重启IIS服务,重写规则依赖该模块才能生效。
- 确认PHP已开启Laravel必填扩展:
openssl、pdo_mysql、mbstring、tokenizer、xml,可通过phpinfo页面验证扩展状态。
最优部署配置(推荐)
直接将IIS站点的物理路径绑定到Laravel项目的public目录,避免项目敏感文件暴露,同时简化重写规则:
- 打开IIS管理器,找到对应站点,右键选择「基本设置」,修改物理路径为Laravel项目下的
public文件夹路径,比如D:\projects\laravel-test\public - 在
public目录下新建或修改web.config文件,替换为如下配置:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="Remove Trailing Slashes" stopProcessing="true"> <match url="^(.*)/$" ignoreCase="false" /> <action type="Redirect" redirectType="Permanent" url="{R:1}" /> </rule> <rule name="Laravel Rewrite" stopProcessing="true"> <match url="^" ignoreCase="false" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> </conditions> <action type="Rewrite" url="index.php" /> </rule> </rules> </rewrite> <staticContent> <remove fileExtension=".woff" /> <remove fileExtension=".woff2" /> <mimeMap fileExtension=".woff" mimeType="font/woff" /> <mimeMap fileExtension=".woff2" mimeType="font/woff2" /> </staticContent> </system.webServer> </configuration>
- 目录权限配置:给整个Laravel项目目录添加
IUSR和IIS_IUSRS用户的读写权限,重点确保storage和bootstrap/cache目录有写入权限。 - 重启IIS站点后访问验证即可。
特殊情况(站点根目录绑定项目根目录)
如果因特殊需求无法绑定到public目录,可在项目根目录放置如下web.config:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="Remove Trailing Slashes" stopProcessing="true"> <match url="^(.*)/$" ignoreCase="false" /> <action type="Redirect" redirectType="Permanent" url="{R:1}" /> </rule> <rule name="Laravel Rewrite to public" stopProcessing="true"> <match url="^" ignoreCase="false" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> </conditions> <action type="Rewrite" url="public/index.php" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
这种方案安全性较低,仅临时调试使用,生产环境务必绑定public目录。
内容的提问来源于stack exchange,提问作者dedik
相关产品推荐
相关产品推荐

