-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-php.ps1
More file actions
95 lines (82 loc) · 3.46 KB
/
install-php.ps1
File metadata and controls
95 lines (82 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# install-php.ps1
# Created: 2025-11-24, dalthonmh (Adapted)
# Description:
# This script downloads and installs PHP for Windows.
# It handles the download, extraction, and initial creation of php.ini.
#
# Requirements:
# - Run with PowerShell.
# - IMPORTANT: Install "Visual C++ Redistributable Visual Studio 2015-2022" first.
#
# Usage:
# .\install-php.ps1
#
# Download this script:
# wget https://raw.githubusercontent.com/dalthonmh/scripts/refs/heads/main/install-php.ps1 -OutFile install-php.ps1
# Parameters
# Versión exacta que deseas (Ej: 8.2.28, 8.3.10, etc.)
$version = "8.2.28"
# Identificador de compilación. Para PHP 8.2+ suele ser "Win32-vs16-x64" (Thread Safe)
# Si quisieras la versión Non-Thread-Safe (NTS), el formato sería "nts-Win32-vs16-x64"
$buildType = "Win32-vs16-x64"
# Construcción automática del nombre del archivo
$zipFilename = "php-$version-$buildType.zip"
$destination = "D:\php"
# URLs: PHP mueve las versiones antiguas a "archives". Intentaremos la URL principal primero.
$mainUrl = "https://windows.php.net/downloads/releases/$zipFilename"
$archiveUrl = "https://windows.php.net/downloads/releases/archives/$zipFilename"
$tempRoot = "$env:TEMP\php_install_temp"
$zipPath = "$tempRoot\php.zip"
Write-Host "Preparing to install PHP $version ($buildType)..."
# Strict validation
if (Test-Path -Path $destination) {
Write-Host "Error: destination folder ($destination) already exists. Aborting."
exit
}
if (Test-Path $tempRoot) { Remove-Item $tempRoot -Recurse -Force }
New-Item -Path $tempRoot -ItemType Directory -Force | Out-Null
Write-Host "Downloading..."
try {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Intentamos descargar de la carpeta principal de releases
try {
Write-Host "Trying main release server..."
Invoke-WebRequest -Uri $mainUrl -OutFile $zipPath -ErrorAction Stop
}
catch {
Write-Host "Version not found in main releases. Trying archives..."
Invoke-WebRequest -Uri $archiveUrl -OutFile $zipPath -ErrorAction Stop
}
}
catch {
Write-Host "Download failed. Please check if version $version exists on windows.php.net"
Write-Error $_
Remove-Item $tempRoot -Recurse -Force
exit
}
# Extract
Write-Host "Extracting..."
Expand-Archive -Path $zipPath -DestinationPath $destination -Force
# Configuración Post-Instalación (php.ini)
Write-Host "Configuring php.ini..."
$phpIniDev = "$destination\php.ini-development"
$phpIniProd = "$destination\php.ini-production"
$phpIni = "$destination\php.ini"
if (Test-Path $phpIniDev) {
Copy-Item -Path $phpIniDev -Destination $phpIni
Write-Host "Created 'php.ini' from 'php.ini-development'"
} elseif (Test-Path $phpIniProd) {
Copy-Item -Path $phpIniProd -Destination $phpIni
Write-Host "Created 'php.ini' from 'php.ini-production'"
} else {
Write-Warning "Could not find php.ini template. You may need to create php.ini manually."
}
# Cleaning
Remove-Item -Path $tempRoot -Recurse -Force
Set-Content -Path "$destination\install-version.txt" -Value "PHP $version ($buildType) installed on $(Get-Date)"
Write-Host "---------------------------------------------------"
Write-Host "PHP installed in $destination"
Write-Host "1. Add '$destination' to your System PATH environment variable."
Write-Host "2. Edit '$destination\php.ini' to enable extensions (uncomment 'extension=...')."
Write-Host "3. Verify installation by running: php -v"
Write-Host "---------------------------------------------------"