|
| 1 | +#Requires -Version 5.1 |
| 2 | +<# |
| 3 | +.SYNOPSIS |
| 4 | + Downloads and installs the latest FrankenPHP release for Windows. |
| 5 | +.DESCRIPTION |
| 6 | + This script downloads the latest FrankenPHP Windows release from GitHub |
| 7 | + and extracts it to the specified directory (~\.frankenphp by default). |
| 8 | +
|
| 9 | + Usage as a one-liner: |
| 10 | + irm https://github.com/php/frankenphp/raw/refs/heads/main/install.ps1 | iex |
| 11 | + Custom install directory: |
| 12 | + $env:FRANKENPHP_INSTALL = 'C:\frankenphp'; irm https://github.com/php/frankenphp/raw/refs/heads/main/install.ps1 | iex |
| 13 | +#> |
| 14 | + |
| 15 | +$ErrorActionPreference = "Stop" |
| 16 | + |
| 17 | +if ($env:FRANKENPHP_INSTALL) { |
| 18 | + $BinDir = $env:FRANKENPHP_INSTALL |
| 19 | +} else { |
| 20 | + $BinDir = Join-Path $HOME ".frankenphp" |
| 21 | +} |
| 22 | + |
| 23 | +Write-Host "Querying latest FrankenPHP release..." -ForegroundColor Cyan |
| 24 | + |
| 25 | +try { |
| 26 | + $release = Invoke-RestMethod -Uri "https://api.github.com/repos/php/frankenphp/releases/latest" |
| 27 | +} catch { |
| 28 | + Write-Host "Could not query GitHub releases: $_" -ForegroundColor Red |
| 29 | + exit 1 |
| 30 | +} |
| 31 | + |
| 32 | +$asset = $release.assets | Where-Object { $_.name -match "Win32-vs17-x64\.zip$" } | Select-Object -First 1 |
| 33 | + |
| 34 | +if (-not $asset) { |
| 35 | + Write-Host "Could not find a Windows release asset." -ForegroundColor Red |
| 36 | + Write-Host "Check https://github.com/php/frankenphp/releases for available downloads." -ForegroundColor Red |
| 37 | + exit 1 |
| 38 | +} |
| 39 | + |
| 40 | +Write-Host "Downloading $($asset.name)..." -ForegroundColor Cyan |
| 41 | + |
| 42 | +$tmpZip = Join-Path $env:TEMP "frankenphp-windows-$PID.zip" |
| 43 | + |
| 44 | +try { |
| 45 | + Invoke-WebRequest -Uri $asset.browser_download_url -OutFile $tmpZip |
| 46 | +} catch { |
| 47 | + Write-Host "Download failed: $_" -ForegroundColor Red |
| 48 | + exit 1 |
| 49 | +} |
| 50 | + |
| 51 | +Write-Host "Extracting to $BinDir..." -ForegroundColor Cyan |
| 52 | + |
| 53 | +if (-not (Test-Path $BinDir)) { |
| 54 | + New-Item -ItemType Directory -Path $BinDir -Force | Out-Null |
| 55 | +} |
| 56 | + |
| 57 | +try { |
| 58 | + Expand-Archive -Force -Path $tmpZip -DestinationPath $BinDir |
| 59 | +} finally { |
| 60 | + Remove-Item $tmpZip -Force -ErrorAction SilentlyContinue |
| 61 | +} |
| 62 | + |
| 63 | +Write-Host "" |
| 64 | +Write-Host "FrankenPHP downloaded successfully to $BinDir" -ForegroundColor Green |
| 65 | + |
| 66 | +# Check if the directory is in PATH |
| 67 | +$inPath = $env:PATH -split ";" | Where-Object { $_ -eq $BinDir -or $_ -eq "$BinDir\" } |
| 68 | +if (-not $inPath) { |
| 69 | + Write-Host "Add $BinDir to your PATH to use frankenphp.exe globally:" -ForegroundColor Yellow |
| 70 | + Write-Host " [Environment]::SetEnvironmentVariable('PATH', `"$BinDir;`" + [Environment]::GetEnvironmentVariable('PATH', 'User'), 'User')" -ForegroundColor Gray |
| 71 | +} |
| 72 | + |
| 73 | +Write-Host "" |
| 74 | +Write-Host "If you like FrankenPHP, please give it a star on GitHub: https://github.com/php/frankenphp" -ForegroundColor Cyan |
0 commit comments