2019-09-06 06:47:43 +07:00
|
|
|
param (
|
|
|
|
[Parameter(Mandatory=$true)][string]$version = "7.3"
|
|
|
|
)
|
|
|
|
|
2019-09-09 07:11:17 +07:00
|
|
|
if($version -eq '7.4') {
|
2019-09-17 22:10:27 +07:00
|
|
|
$version = '7.4RC'
|
2019-09-09 07:11:17 +07:00
|
|
|
}
|
2019-09-21 23:06:03 +07:00
|
|
|
|
2019-10-08 19:42:54 +07:00
|
|
|
Write-Host "Installing PhpManager" -ForegroundColor Blue
|
2019-09-06 06:47:43 +07:00
|
|
|
Install-Module -Name PhpManager -Force -Scope CurrentUser
|
2019-09-17 22:10:27 +07:00
|
|
|
|
2019-09-21 23:06:03 +07:00
|
|
|
$installed = $($(php -v)[0] -join '')[4..6] -join ''
|
2019-09-17 22:10:27 +07:00
|
|
|
if($installed -ne $version) {
|
|
|
|
if($version -lt '7.0') {
|
2019-10-08 19:42:54 +07:00
|
|
|
Write-Host "Installing VcRedist"
|
2019-09-17 22:10:27 +07:00
|
|
|
Install-Module -Name VcRedist -Force
|
|
|
|
}
|
2019-10-08 19:42:54 +07:00
|
|
|
Write-Host "Installing PHP" -ForegroundColor Blue
|
2019-09-17 22:10:27 +07:00
|
|
|
Uninstall-Php C:\tools\php
|
2019-09-21 23:06:03 +07:00
|
|
|
Install-Php -Version $version -Architecture x86 -ThreadSafe $true -InstallVC -Path C:\tools\php$version -TimeZone UTC -InitialPhpIni Production -Force
|
2019-10-08 19:42:54 +07:00
|
|
|
Write-Host "Switch PHP" -ForegroundColor Blue
|
2019-09-17 22:10:27 +07:00
|
|
|
(Get-PhpSwitcher).targets
|
|
|
|
Initialize-PhpSwitcher -Alias C:\tools\php -Scope CurrentUser -Force
|
|
|
|
Add-PhpToSwitcher -Name $version -Path C:\tools\php$version -Force
|
|
|
|
Switch-Php $version -Force
|
2019-09-21 23:06:03 +07:00
|
|
|
}
|
|
|
|
|
2019-10-08 19:42:54 +07:00
|
|
|
Write-Host "Housekeeping in PHP.ini, enabling openssl" -ForegroundColor Blue
|
2019-10-04 15:00:16 +07:00
|
|
|
$ext_dir = "C:\tools\php\ext"
|
2019-09-21 23:06:03 +07:00
|
|
|
Add-Content C:\tools\php\php.ini "date.timezone = 'UTC'"
|
2019-10-04 15:00:16 +07:00
|
|
|
Set-PhpIniKey extension_dir $ext_dir
|
|
|
|
|
2019-09-21 23:06:03 +07:00
|
|
|
if($version -lt '7.4') {
|
|
|
|
Enable-PhpExtension openssl
|
|
|
|
} else {
|
|
|
|
Add-Content C:\tools\php\php.ini "extension=php_openssl.dll"
|
2019-10-04 15:00:16 +07:00
|
|
|
Copy-Item "php_pcov.dll" -Destination $ext_dir"\php_pcov.dll"
|
2019-09-09 07:11:17 +07:00
|
|
|
}
|
2019-09-17 22:10:27 +07:00
|
|
|
|
2019-10-08 19:42:54 +07:00
|
|
|
Write-Host "Installing Composer" -ForegroundColor Blue
|
2019-09-07 19:31:50 +07:00
|
|
|
Install-Composer -Scope System -Path C:\tools\php
|
2019-09-06 06:47:43 +07:00
|
|
|
php -v
|
2019-10-11 06:11:25 +07:00
|
|
|
composer -V
|
|
|
|
|
|
|
|
Function Add-Extension($extension, $install_command, $prefix, $log_prefix)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$exist = Test-Path -Path C:\tools\php\ext\php_$extension.dll
|
|
|
|
if(!(php -m | findstr -i ${extension}) -and $exist) {
|
|
|
|
Add-Content C:\tools\php\php.ini "$prefix=php_$extension.dll"
|
|
|
|
Write-Host "$log_prefix`: Enabled $extension" -ForegroundColor green
|
|
|
|
} elseif(php -m | findstr -i $extension) {
|
|
|
|
Write-Host "$log_prefix`: $extension was already enabled" -ForegroundColor yellow
|
|
|
|
}
|
|
|
|
} catch [Exception] {
|
|
|
|
Write-Host "$log_prefix`: $extension could not be enabled" -ForegroundColor red
|
|
|
|
}
|
|
|
|
|
|
|
|
$status = 404
|
|
|
|
try {
|
|
|
|
$status = (Invoke-WebRequest -Uri "https://pecl.php.net/json.php?package=$extension" -UseBasicParsing -DisableKeepAlive).StatusCode
|
|
|
|
} catch [Exception] {
|
|
|
|
$status = 500
|
|
|
|
}
|
|
|
|
|
|
|
|
if($status -eq 200) {
|
|
|
|
if(!(php -m | findstr -i $extension)) {
|
|
|
|
try {
|
|
|
|
Invoke-Expression $install_command
|
|
|
|
Write-Host "$log_prefix`: Installed and enabled $extension" -ForegroundColor green
|
|
|
|
} catch [Exception] {
|
|
|
|
Write-Host "$log_prefix`: Could not install $extension on PHP $version" -ForegroundColor red
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(!(php -m | findstr -i $extension)) {
|
|
|
|
Write-Host "$log_prefix`: Could not find $extension for PHP$version on PECL" -ForegroundColor red
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|