You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

挂载PHP项目至Windows容器IIS后无法运行问题求助

挂载PHP项目至Windows容器IIS后无法运行问题求助

大家好,我在Windows Server Core容器里搭建了IIS环境,并且把本地项目目录挂载到了容器的C:\inetpub\wwwroot路径下,但运行项目时PHP一直弹出以下警告:

PHP Warning: Unknown: Failed to open stream: No such file or directory in Unknown on line 0

但奇怪的是,如果我用命令把一段简单的PHP代码写入wwwroot里的index.php,这个文件却能正常运行。

下面是我的相关配置文件内容:

Dockerfile

# escape=`

#
# This Dockerfile is provided for demonstration purposes only and it is not supported by Microsoft
# PHP 8.1 x64 running on IIS
#
FROM mcr.microsoft.com/windows/servercore/iis AS php81

COPY dev/php.zip /

COPY create-php-directory.ps1 /install-iis.ps1

COPY VC_redist.x64.exe /vc_redist.x64.exe

COPY url_rewrite.msi /url_rewrite.msi

COPY PowerShell7.msi /PowerShell7.msi

COPY configure-iis.bat /configure-iis.bat

#SHELL ["cmd"]

#RUN msiexec.exe /package C:\PowerShell7.msi /quiet ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ADD_FILE_CONTEXT_MENU_RUNPOWERSHELL=1 ENABLE_PSREMOTING=1 REGISTER_MANIFEST=1 USE_MU=1 ENABLE_MU=1 ADD_PATH=1

#SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop';"]

#WORKDIR C:\

RUN powershell .\install-iis.ps1

#
# Enable required IIS Features
# Install VC Redist 14
# Configure IIS
# Configure system PATH
#

RUN .\configure-iis.bat

EXPOSE 80

EXPOSE 443

# Optional: Add a starter page
#RUN powershell.exe -Command "'<?php phpinfo(); ?>' | Out-File C:\inetpub\wwwroot\index.php -Encoding UTF8"

configure-iis.bat

dism.exe /Online /Enable-Feature /FeatureName:IIS-CGI /All

C:\vc_redist.x64.exe /quiet /install

del C:\vc_redist.x64.exe

msiexec.exe /package c:\PowerShell7.msi /quiet ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ADD_FILE_CONTEXT_MENU_RUNPOWERSHELL=1 ENABLE_PSREMOTING=1 REGISTER_MANIFEST=1 USE_MU=1 ENABLE_MU=1 ADD_PATH=1

del C:\PowerShell7.msi

msiexec /i c:\url_rewrite.msi /quiet /qn /norestart

del C:\url_rewrite.msi

C:\Windows\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+[fullPath='c:\PHP\v8.1\php-cgi.exe',requestTimeout='3600',activityTimeout='3600',instanceMaxRequests='10000']

C:\Windows\system32\inetsrv\appcmd.exe set config -section:system.webServer/handlers /+[name='PHP_via_FastCGI',path='*.php',verb='*',modules='FastCgiModule',scriptProcessor='c:\PHP\v8.1\php-cgi.exe',resourceType='Either',requireAccess='Script']

C:\Windows\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+[fullPath='c:\PHP\v8.1\php-cgi.exe'].environmentVariables.[name='PHP_FCGI_MAX_REQUESTS',value='10000']

C:\Windows\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+[fullPath='c:\PHP\v8.1\php-cgi.exe'].environmentVariables.[name='PHPRC',value='C:\PHP\v8.1']

C:\Windows\system32\inetsrv\appcmd.exe set config -section:defaultDocument /enabled:true /+files.[value='index.php']

setx PATH /M %PATH%;C:\PHP\v8.1

setx PHP /M "C:\PHP\v8.1"

del C:\inetpub\wwwroot\* /Q

docker-compose.yml

version: "3"

services:
  iis:
    build: ./docker/iis-php
    ports:
      - "8080:80"
    volumes:
      - .:C:\inetpub\wwwroot
#      - ..\PHP:C:\PHP\LOG
      - iisphp:C:\PHP\LOG

volumes:
  iisphp:

我期望项目能正常运行,有没有大佬能帮忙看看问题出在哪?

备注:内容来源于stack exchange,提问作者Babatunde

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.22 15:35:30