安装在IIS上的PHP项目Windows容器无法运行

nmpmafwu  于 2023-05-05  发布在  PHP
关注(0)|答案(1)|浏览(177)

我在windows servercore容器上设置了IIS,并将我的项目目录挂载到wwwroot。当我运行这个项目时,我一直收到来自PHP的以下警告:
PHP警告:未知:无法打开流:第0行未知中没有此类文件或目录
然而,当我将index.php回显到wwwroot时,它运行得很好。
下面是我的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:

预计该项目将按预期运行。

w1jd8yoj

w1jd8yoj1#

这个错误有很多原因,首先请检查文件的路径是否正确,错误意味着php-cgi.exe没有适当的权限。请使用进程监视器,查看哪个用户对此进程的访问被拒绝,并给予相应的权限。

相关问题