You've already forked Atomcms-edit
97 lines
3.2 KiB
PowerShell
Executable File
97 lines
3.2 KiB
PowerShell
Executable File
# Uitgebreide PHP locatie detector voor IIS web.config
|
|
|
|
$searchPaths = @(
|
|
"C:\PHP",
|
|
"C:\Program Files\PHP",
|
|
"C:\Program Files (x86)\PHP",
|
|
"C:\php7",
|
|
"C:\php8",
|
|
"C:\xampp\php",
|
|
"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
|
|
|
|
# Methode 1: Check of php-cgi.exe in PATH staat
|
|
Write-Host "Zoeken naar php-cgi.exe..." -ForegroundColor Cyan
|
|
$phpPath = (Get-Command php-cgi.exe -ErrorAction SilentlyContinue).Source
|
|
|
|
# Methode 2: Zoek in standaard locaties
|
|
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
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
# Methode 3: Zoek in alle C: schijf (alleen top-level folders voor snelheid)
|
|
if (-not $phpPath) {
|
|
Write-Host "Zoeken in C:\ schijf..." -ForegroundColor Yellow
|
|
$rootFolders = Get-ChildItem -Path "C:\" -Directory -ErrorAction SilentlyContinue |
|
|
Where-Object { $_.Name -match 'php|xampp|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
|
|
}
|
|
}
|
|
}
|
|
|
|
# Methode 4: Check Windows Registry voor PHP installaties
|
|
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 "`nGevonden: $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 succesvol geupdate in web.config!" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "Handler was al correct ingesteld." -ForegroundColor Yellow
|
|
}
|
|
} else {
|
|
Write-Host "web.config niet gevonden in huidige directory!" -ForegroundColor Red
|
|
}
|
|
} else {
|
|
Write-Host "`nKon php-cgi.exe niet vinden." -ForegroundColor Red
|
|
Write-Host "Controleer of PHP correct is geinstalleerd." -ForegroundColor Red
|
|
}
|