2019-09-06 05:17:43 +05:30
|
|
|
param (
|
2019-12-09 08:09:03 +05:30
|
|
|
[Parameter(Mandatory = $true)][string]$version = "7.3"
|
2019-09-06 05:17:43 +05:30
|
|
|
)
|
|
|
|
|
2019-10-17 01:41:13 +05:30
|
|
|
$tick = ([char]8730)
|
|
|
|
$cross = ([char]10007)
|
2019-11-25 11:53:13 +01:00
|
|
|
$php_dir = 'C:\tools\php'
|
2019-10-17 01:41:13 +05:30
|
|
|
|
|
|
|
Function Step-Log($message) {
|
2019-10-23 15:27:40 +05:30
|
|
|
printf "\n\033[90;1m==> \033[0m\033[37;1m%s \033[0m\n" $message
|
2019-10-17 01:41:13 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
Function Add-Log($mark, $subject, $message) {
|
2019-11-25 11:53:13 +01:00
|
|
|
$code = if ($mark -eq $cross) { "31" } else { "32" }
|
2019-10-23 15:27:40 +05:30
|
|
|
printf "\033[%s;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" $code $mark $subject $message
|
2019-10-17 01:41:13 +05:30
|
|
|
}
|
|
|
|
|
2019-12-09 08:09:03 +05:30
|
|
|
if ($version -eq '8.0') {
|
|
|
|
$version = '7.4'
|
|
|
|
}
|
|
|
|
|
2019-10-17 01:41:13 +05:30
|
|
|
Step-Log "Setup PhpManager"
|
2019-09-06 05:17:43 +05:30
|
|
|
Install-Module -Name PhpManager -Force -Scope CurrentUser
|
2019-10-17 01:41:13 +05:30
|
|
|
Add-Log $tick "PhpManager" "Installed"
|
2019-09-17 20:40:27 +05:30
|
|
|
|
2019-11-25 11:53:13 +01:00
|
|
|
$installed = $null
|
|
|
|
if (Test-Path -LiteralPath $php_dir -PathType Container) {
|
|
|
|
try {
|
|
|
|
$installed = Get-Php -Path $php_dir
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
}
|
|
|
|
}
|
2019-10-17 01:41:13 +05:30
|
|
|
Step-Log "Setup PHP and Composer"
|
2019-11-25 11:53:13 +01:00
|
|
|
if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version -replace '^(\d+(\.\d+)*).*', '$1.')))) {
|
|
|
|
if ($version -lt '7.0') {
|
2019-09-17 20:40:27 +05:30
|
|
|
Install-Module -Name VcRedist -Force
|
|
|
|
}
|
2019-11-28 06:10:27 +05:30
|
|
|
|
2019-11-25 11:53:13 +01:00
|
|
|
Install-Php -Version $version -Architecture x86 -ThreadSafe $true -InstallVC -Path $php_dir -TimeZone UTC -InitialPhpIni Production -Force >$null 2>&1
|
|
|
|
$installed = Get-Php -Path $php_dir
|
|
|
|
$status = "Installed PHP $($installed.FullVersion)"
|
|
|
|
}
|
|
|
|
else {
|
2019-11-30 05:58:14 +05:30
|
|
|
$status = "PHP $($installed.FullVersion) Found"
|
2019-09-21 21:36:03 +05:30
|
|
|
}
|
|
|
|
|
2019-11-25 11:53:13 +01:00
|
|
|
Set-PhpIniKey -Key 'date.timezone' -Value 'UTC' -Path $php_dir
|
|
|
|
Enable-PhpExtension -Extension openssl, curl -Path $php_dir
|
2019-11-29 10:52:07 +05:30
|
|
|
Update-PhpCAInfo -Path $php_dir -Source CurrentUser
|
2019-10-17 01:41:13 +05:30
|
|
|
Add-Log $tick "PHP" $status
|
2019-09-17 20:40:27 +05:30
|
|
|
|
2019-11-25 11:53:13 +01:00
|
|
|
Install-Composer -Scope System -Path $php_dir -PhpPath $php_dir
|
2019-10-17 01:41:13 +05:30
|
|
|
Add-Log $tick "Composer" "Installed"
|
2019-10-11 04:41:25 +05:30
|
|
|
|
2019-11-25 16:35:11 +01:00
|
|
|
Function Add-Extension {
|
|
|
|
Param (
|
|
|
|
[Parameter(Position = 0, Mandatory = $true)]
|
|
|
|
[ValidateNotNull()]
|
|
|
|
[ValidateLength(1, [int]::MaxValue)]
|
|
|
|
[string]
|
|
|
|
$extension,
|
|
|
|
[Parameter(Position = 1, Mandatory = $false)]
|
|
|
|
[ValidateNotNull()]
|
|
|
|
[ValidateSet('stable', 'beta', 'alpha', 'devel', 'snapshot')]
|
|
|
|
[string]
|
|
|
|
$mininum_stability = 'stable'
|
|
|
|
)
|
2019-10-11 04:41:25 +05:30
|
|
|
try {
|
2019-11-25 11:53:13 +01:00
|
|
|
$extension_info = Get-PhpExtension -Path $php_dir | Where-Object { $_.Name -eq $extension -or $_.Handle -eq $extension }
|
|
|
|
if ($null -ne $extension_info) {
|
|
|
|
switch ($extension_info.State) {
|
|
|
|
'Builtin' {
|
|
|
|
Add-Log $tick $extension "Enabled"
|
|
|
|
}
|
|
|
|
'Enabled' {
|
|
|
|
Add-Log $tick $extension "Enabled"
|
|
|
|
}
|
|
|
|
default {
|
|
|
|
Enable-PhpExtension -Extension $extension_info.Handle -Path $php_dir
|
|
|
|
Add-Log $tick $extension "Enabled"
|
|
|
|
}
|
2019-10-11 04:41:25 +05:30
|
|
|
}
|
|
|
|
}
|
2019-11-25 11:53:13 +01:00
|
|
|
else {
|
2019-11-25 14:03:28 +01:00
|
|
|
Install-PhpExtension -Extension $extension -MinimumStability $mininum_stability -Path $php_dir
|
2019-11-25 21:55:52 +05:30
|
|
|
Add-Log $tick $extension "Installed and enabled"
|
2019-10-11 04:41:25 +05:30
|
|
|
}
|
|
|
|
}
|
2019-11-25 11:53:13 +01:00
|
|
|
catch {
|
2019-12-09 08:09:03 +05:30
|
|
|
Add-Log $cross $extension "Could not install $extension on PHP $($installed.FullVersion)"
|
2019-11-25 11:53:13 +01:00
|
|
|
}
|
|
|
|
}
|