Last active
September 24, 2019 07:26
-
-
Save soup-bowl/7d0bb07847b5c3ab30445cce6518802d to your computer and use it in GitHub Desktop.
Quick & dirty script to grab a new copy of PHP and Microsoft SQL Plugin and swaps over config to the upgrade.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[Parameter(Mandatory=$true)][string]$version | |
) | |
if( Test-Path -Path ".\upgrade-php.xml" ) { | |
[xml]$configFile= get-content ".\upgrade-php.xml"; | |
foreach ($option in $configFile.configuration.config) { | |
New-variable -Name $option.key -Value $option.value; | |
} | |
} else { | |
Write-Host "No upgrade-php.xml configuration found. Exiting."; | |
return; | |
} | |
if( Test-Path -Path "${destination}\${version}" ) { | |
Write-Host "Version ${version} already exists. Exiting."; | |
return; | |
} | |
Write-Host "Downloading PHP ${version} from windows.php.net."; | |
try { | |
Invoke-WebRequest https://windows.php.net/downloads/releases/php-$version-nts-Win32-VC15-x64.zip -OutFile "${destination}\php.zip"; | |
} catch { | |
Write-Host "Not found in release. Looking in archives."; | |
try { | |
Invoke-WebRequest https://windows.php.net/downloads/releases/archives/php-$version-nts-Win32-VC15-x64.zip -OutFile "${destination}\php.zip"; | |
} catch { | |
Write-Host "Not found in archive. Exiting."; | |
return; | |
} | |
} | |
Expand-Archive -Path "${destination}\php.zip" -DestinationPath "${destination}\${version}"; | |
Remove-Item -Path "${destination}\php.zip"; | |
$versionSplit = $version.split("."); | |
$versionSplit[2] = $versionSplit[2] - 1; | |
$previousVersion = $versionSplit -join "."; | |
if( Test-Path -Path "${destination}\${previousVersion}" ) { | |
Write-Host "Coping configuration file from ${previousVersion}."; | |
Copy-Item -Path "${destination}\${previousVersion}\php.ini" -Destination "${destination}\${version}\php.ini" | |
} else { | |
Write-Host "No previous version was found. Initating config with default settings."; | |
Copy-Item -Path "${destination}\${version}\php.ini-production" -Destination "${destination}\${version}\php.ini" | |
} | |
Write-Host "Downloading Microsoft SQL Drivers for PHP from GitHub."; | |
$masver = "$($versionSplit[0]).$($versionSplit[1])"; | |
Invoke-WebRequest https://github.com/microsoft/msphpsql/releases/download/v$phpmssqlversion/Windows-$masver.zip -OutFile "${destination}\mssql_driver.zip"; | |
Expand-Archive -Path "${destination}\mssql_driver.zip" -DestinationPath "${destination}\mssql_driver"; | |
Remove-Item -Path "${destination}\mssql_driver.zip"; | |
Copy-Item -Path "${destination}\mssql_driver\Windows-${masver}\x64\*_nts.dll" -Destination "${destination}\${version}\ext\" -Recurse; | |
Remove-Item -Path "${destination}\mssql_driver" -Recurse; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<configuration> | |
<config key="destination" value=".\php" /> | |
<config key="phpmssqlversion" value="5.6.1" /> | |
</configuration> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment