Skip to content

Commit 4feef07

Browse files
committed
fix: os.execute(installCmd)
1 parent 77be584 commit 4feef07

2 files changed

Lines changed: 72 additions & 5 deletions

File tree

bin/install-windows-php.ps1

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,27 +140,86 @@ Function Get-PhpExtras {
140140
return $false
141141
}
142142

143+
Function Write-PathInfo {
144+
param(
145+
[Parameter(Mandatory = $true)][string]$Label,
146+
[Parameter(Mandatory = $true)][string]$Path
147+
)
148+
149+
$exists = Test-Path $Path
150+
if ($exists) {
151+
$item = Get-Item $Path -ErrorAction SilentlyContinue
152+
$kind = if ($item -and $item.PSIsContainer) { "Directory" } elseif ($item) { "File" } else { "Unknown" }
153+
Write-Host ("{0}: {1} (exists=True, kind={2})" -f $Label, $Path, $kind)
154+
} else {
155+
Write-Host ("{0}: {1} (exists=False)" -f $Label, $Path)
156+
}
157+
}
158+
159+
Function Write-ValueInfo {
160+
param(
161+
[Parameter(Mandatory = $true)][string]$Label,
162+
[Parameter(Mandatory = $true)]$Value
163+
)
164+
165+
$typeName = if ($null -eq $Value) { "<null>" } else { $Value.GetType().FullName }
166+
Write-Host ("{0}: {1} (type={2})" -f $Label, $Value, $typeName)
167+
}
168+
143169
$tempFile = [IO.Path]::ChangeExtension([IO.Path]::GetTempFileName(), '.zip')
144170

145171
try {
146-
if (-not (Test-Path $CustomPath)) { New-Item -ItemType Directory -Path $CustomPath | Out-Null }
172+
Set-Location -LiteralPath $env:TEMP
173+
Write-ValueInfo "Version" $Version
174+
Write-ValueInfo "Arch" $Arch
175+
Write-ValueInfo "ThreadSafe" $ThreadSafe
176+
Write-ValueInfo "Timezone" $Timezone
177+
Write-PathInfo "CustomPath input" $CustomPath
178+
Write-PathInfo "Temp archive file" $tempFile
179+
180+
if (-not (Test-Path $CustomPath)) {
181+
Write-Host "Creating CustomPath directory: $CustomPath"
182+
New-Item -ItemType Directory -Path $CustomPath | Out-Null
183+
}
147184

148185
$Semver = $Version
149186
$installDirectory = [Environment]::ExpandEnvironmentVariables($CustomPath)
150187

151-
Write-Host "Downloading PHP $Semver ($Arch, $(if($ThreadSafe){'ts'}else{'nts'})) -> $installDirectory"
188+
Write-PathInfo "Install directory" $installDirectory
189+
Write-Host ("Downloading PHP {0} ({1}, {2}) -> {3}" -f $Semver, $Arch, $(if($ThreadSafe){'ts'}else{'nts'}), $installDirectory)
152190
Get-PhpFromUrl $Semver $Semver $Arch $ThreadSafe $tempFile
191+
Write-PathInfo "Downloaded archive" $tempFile
153192
Expand-Archive -Path $tempFile -DestinationPath $installDirectory -Force -ErrorAction Stop
193+
Write-Host "Archive expanded to: $installDirectory"
194+
Write-Host "Top-level contents after unpack:"
195+
Get-ChildItem -LiteralPath $installDirectory -Force | ForEach-Object {
196+
Write-Host (" {0} [{1}]" -f $_.FullName, $(if ($_.PSIsContainer) { "Directory" } else { "File" }))
197+
}
198+
199+
$phpExe = Join-Path $installDirectory "php.exe"
200+
$phpIniProdAfterUnpack = Join-Path $installDirectory "php.ini-production"
201+
$phpIniRecommendedAfterUnpack = Join-Path $installDirectory "php.ini-recommended"
202+
$extDirAfterUnpack = Join-Path $installDirectory "ext"
203+
204+
Write-PathInfo "php.exe after unpack" $phpExe
205+
Write-PathInfo "php.ini-production after unpack" $phpIniProdAfterUnpack
206+
Write-PathInfo "php.ini-recommended after unpack" $phpIniRecommendedAfterUnpack
207+
Write-PathInfo "ext directory after unpack" $extDirAfterUnpack
154208

155209
# Download extras package (additional extension DLLs)
156210
if ($InstallExtras) {
157211
Write-Host "Downloading PHP extras package..."
158212
$tempExtras = [IO.Path]::ChangeExtension([IO.Path]::GetTempFileName(), '.zip')
159213
try {
214+
Write-PathInfo "Temp extras archive" $tempExtras
160215
$found = Get-PhpExtras $Semver $Semver $Arch $tempExtras
161216
if ($found) {
162217
Expand-Archive -Path $tempExtras -DestinationPath $installDirectory -Force -ErrorAction Stop
163218
Write-Host "Extras installed successfully."
219+
Write-Host "Top-level contents after extras unpack:"
220+
Get-ChildItem -LiteralPath $installDirectory -Force | ForEach-Object {
221+
Write-Host (" {0} [{1}]" -f $_.FullName, $(if ($_.PSIsContainer) { "Directory" } else { "File" }))
222+
}
164223
} else {
165224
Write-Host "Warning: No extras package found for PHP $Semver - skipping."
166225
}
@@ -172,6 +231,7 @@ try {
172231
}
173232

174233
$extDir = Join-Path $installDirectory "ext"
234+
Write-PathInfo "ext directory" $extDir
175235

176236
# Warn if ext/ directory is missing (incomplete build)
177237
if (-not (Test-Path $extDir)) {
@@ -183,15 +243,20 @@ try {
183243
$phpIniProd = Join-Path $installDirectory "php.ini-production"
184244
if (-not (Test-Path $phpIniProd)) { $phpIniProd = Join-Path $installDirectory "php.ini-recommended" }
185245
$phpIni = Join-Path $installDirectory "php.ini"
246+
Write-PathInfo "php.ini-production/recommended" $phpIniProd
247+
Write-PathInfo "php.ini target" $phpIni
186248

187249
if (Test-Path $phpIniProd) {
188250
Copy-Item $phpIniProd $phpIni -Force
251+
Write-Host "Copied php.ini template to: $phpIni"
189252

190253
(Get-Content $phpIni) -replace '^extension_dir = "./"', "extension_dir = `"$extDir`"" | Set-Content $phpIni
191254
(Get-Content $phpIni) -replace ';\s?extension_dir = "ext"', "extension_dir = `"$extDir`"" | Set-Content $phpIni
192255
(Get-Content $phpIni) -replace ';\s?date.timezone =', "date.timezone = `"$Timezone`"" | Set-Content $phpIni
256+
Write-Host "Updated php.ini with extension_dir and timezone."
193257

194258
if (Test-Path $extDir) {
259+
Write-Host "Probing static extensions from: $phpExe"
195260
$staticExtensions = (& "$installDirectory\php.exe" -m 2>$null) -split "`n" |
196261
ForEach-Object { $_.Trim().ToLower() }
197262

@@ -215,8 +280,10 @@ try {
215280
foreach ($ext in $zendExtensions) {
216281
$dllPath = Join-Path $extDir "php_$ext.dll"
217282
$isStatic = $staticExtensions -contains $ext.ToLower()
283+
Write-PathInfo "Zend extension candidate" $dllPath
218284
if (-not $isStatic -and (Test-Path $dllPath)) {
219285
(Get-Content $phpIni) -replace "^;zend_extension=$ext", "zend_extension=$ext" | Set-Content $phpIni
286+
Write-Host "Enabled zend extension: $ext"
220287
}
221288
}
222289
}
@@ -236,6 +303,7 @@ try {
236303
}
237304

238305
Set-PathEntryFirst -Target 'User' -Entry $installDirectory
306+
Write-Host "PATH updated with: $installDirectory"
239307

240308
Write-Host ""
241309
Write-Host "Installed PHP $Semver directly to $installDirectory"

hooks/post_install.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ function install_php_for_windows(sdkPath, version)
3333
major, minor = tonumber(major) or 0, tonumber(minor) or 0
3434

3535
local scriptPath = assert(RUNTIME.pluginDirPath .. "\\bin\\install-windows-php.ps1")
36-
local installCmd = string.format([[
37-
powershell -NoProfile -ExecutionPolicy Bypass -Command "Set-Location -LiteralPath $env:TEMP; & '%s' -Version '%s' -Arch x64 -CustomPath '%s'"
38-
]],
36+
local installCmd = string.format(
37+
[[powershell -NoProfile -ExecutionPolicy Bypass -File %s -Version %s -Arch x64 -CustomPath %s]],
3938
scriptPath,
4039
version,
4140
sdkPath

0 commit comments

Comments
 (0)