# Extended PHP location detector for IIS web.config $searchPaths = @( "C:\PHP", "C:\Program Files\PHP", "C:\Program Files (x86)\PHP", "C:\php7", "C:\php8", "C:\wamp\bin\php", "C:\wamp64\bin\php", "C:\laragon\bin\php", "C:\inetpub\wwwroot\php", "C:\inetpub\wwwroot\PHP", "C:\inetpub\php", "C:\inetpub\PHP", "$env:SystemDrive\inetpub\wwwroot\php", "$env:SystemDrive\inetpub\php" ) $phpPath = $null # Method 1: Check if php-cgi.exe is in PATH Write-Host "Searching for php-cgi.exe..." -ForegroundColor Cyan $phpPath = (Get-Command php-cgi.exe -ErrorAction SilentlyContinue).Source # Method 2: Search in default locations if (-not $phpPath) { foreach ($basePath in $searchPaths) { if (Test-Path $basePath) { $found = Get-ChildItem -Path $basePath -Recurse -Filter "php-cgi.exe" -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName if ($found) { $phpPath = $found break } } } } # Method 3: Search entire C: drive (top-level folders only for speed) if (-not $phpPath) { Write-Host "Searching C:\ drive..." -ForegroundColor Yellow $rootFolders = Get-ChildItem -Path "C:\" -Directory -ErrorAction SilentlyContinue | Where-Object { $_.Name -match 'php|wamp|laragon|inetpub' } foreach ($folder in $rootFolders) { $found = Get-ChildItem -Path $folder.FullName -Recurse -Filter "php-cgi.exe" -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName if ($found) { $phpPath = $found break } } } # Method 4: Check Windows Registry for PHP installations if (-not $phpPath) { $regPaths = @( "HKLM:\SOFTWARE\PHP", "HKLM:\SOFTWARE\Wow6432Node\PHP" ) foreach ($regPath in $regPaths) { if (Test-Path $regPath) { $installDir = (Get-ItemProperty -Path $regPath -Name "InstallDir" -ErrorAction SilentlyContinue).InstallDir if ($installDir) { $candidate = Join-Path $installDir "php-cgi.exe" if (Test-Path $candidate) { $phpPath = $candidate break } } } } } if ($phpPath) { Write-Host "`nFound: $phpPath" -ForegroundColor Green $webConfigPath = ".\web.config" if (Test-Path $webConfigPath) { $content = Get-Content $webConfigPath -Raw $newContent = $content -replace 'scriptProcessor="[^"]*"', "scriptProcessor=`"$phpPath`"" if ($content -ne $newContent) { $newContent | Set-Content $webConfigPath -NoNewline Write-Host "Handler successfully updated in web.config!" -ForegroundColor Green } else { Write-Host "Handler was already set correctly." -ForegroundColor Yellow } } else { Write-Host "web.config not found in current directory!" -ForegroundColor Red } } else { Write-Host "`nCould not find php-cgi.exe." -ForegroundColor Red Write-Host "Check if PHP is installed correctly." -ForegroundColor Red }