@@ -697,15 +697,17 @@ jobs:
697697 Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerRole, IIS-WebServer, IIS-CommonHttpFeatures, IIS-ManagementConsole, IIS-HttpErrors, IIS-HttpRedirect, IIS-WindowsAuthentication, IIS-StaticContent, IIS-DefaultDocument, IIS-HttpCompressionStatic, IIS-DirectoryBrowsing, IIS-WebServerManagementTools, IIS-CGI -All
698698 Set-Service wuauserv -StartupType Manual
699699 $webConfig = "${env:GITHUB_WORKSPACE}\phpBB3\phpBB\web.config"
700- $content = Get-Content $webConfig -Raw
701- $content = $content.Replace(
702- "<configuration>",
703- "<configuration>`n`t<system.web>`n`t`t<customErrors mode=`"Off`"/>`n`t</system.web>"
704- )
705- $content = $content.Replace(
706- "`t</system.webServer>",
707- "`t`t<httpErrors errorMode=`"Detailed`" />`n`t</system.webServer>"
708- )
700+ [xml]$webConfigXml = Get-Content $webConfig -Raw
701+ $configuration = $webConfigXml.SelectSingleNode('/configuration')
702+ $systemWebServer = $webConfigXml.SelectSingleNode('/configuration/system.webServer')
703+ $systemWeb = $webConfigXml.CreateElement('system.web')
704+ $customErrors = $webConfigXml.CreateElement('customErrors')
705+ $customErrors.SetAttribute('mode', 'Off')
706+ [void]$systemWeb.AppendChild($customErrors)
707+ [void]$configuration.InsertBefore($systemWeb, $systemWebServer)
708+ $httpErrors = $webConfigXml.CreateElement('httpErrors')
709+ $httpErrors.SetAttribute('errorMode', 'Detailed')
710+ [void]$systemWebServer.AppendChild($httpErrors)
709711 $rewriteInstalled = $false
710712 try {
711713 choco install urlrewrite -y --no-progress
@@ -714,9 +716,12 @@ jobs:
714716 Write-Warning "URL Rewrite installation failed; continuing without rewrite-specific IIS configuration."
715717 }
716718 if (-not $rewriteInstalled) {
717- $content = $content -replace "(?s)`r?`n\s*<rewrite>.*?</rewrite>", ""
719+ $rewrite = $webConfigXml.SelectSingleNode('/configuration/system.webServer/rewrite')
720+ if ($null -ne $rewrite) {
721+ [void]$systemWebServer.RemoveChild($rewrite)
722+ }
718723 }
719- Set-Content $webConfig -Value $content -Encoding UTF8
724+ $webConfigXml.Save($webConfig)
720725 Import-Module WebAdministration
721726 New-WebSite -Name 'phpBBTest' -PhysicalPath "${env:GITHUB_WORKSPACE}\phpBB3\phpBB" -Force
722727 $session = Get-PSSession -Name WinPSCompatSession
@@ -728,7 +733,7 @@ jobs:
728733 [System.Environment]::SetEnvironmentVariable('PATH',$Env:PATH+";%windir%\system32\inetsrv")
729734 echo Setup FAST-CGI configuration
730735 Add-WebConfiguration -Filter /system.webServer/fastCgi -PSPath IIS:\ -Value @{fullpath="C:\tools\php\php-cgi.exe"}
731- echo Setup FACT -CGI handler
736+ echo Setup FAST -CGI handler
732737 New-WebHandler -Name "PHP-FastCGI" -Path "*.php" -Modules FastCgiModule -ScriptProcessor "C:\tools\php\php-cgi.exe" -Verb '*' -ResourceType Either
733738 iisreset
734739 NET START W3SVC
0 commit comments