-
-
Save renekreijveld/58e255f475068bfb785cf3f2d1b0a503 to your computer and use it in GitHub Desktop.
S
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
#!/bin/bash | |
# PHP switcher for Homebrew based NginX, MariaDB, PHP development stack | |
# Written by: René Kreijveld, 17/07/2027 | |
# Based on the work of Phil Cook and Andy Miller. | |
homebrew_path=$(brew --prefix) | |
brew_array=("7.4","8.1","8.2","8.3","8.4") | |
php_array=("[email protected]" "[email protected]" "[email protected]" "[email protected]" "[email protected]") | |
php_version="php@$1" | |
requested_version=$1 | |
# What versions of php are installed via brew | |
for i in ${php_array[*]}; do | |
version=$(echo "$i" | sed 's/^php@//') | |
if [[ -d "$homebrew_path/etc/php/$version" ]]; then | |
php_installed_array+=("$i") | |
fi | |
done | |
# Check that the requested version is supported | |
if [[ " ${php_array[*]} " == *"$php_version"* ]]; then | |
# Check that the requested version is installed | |
if [[ " ${php_installed_array[*]} " == *"$php_version"* ]]; then | |
echo "PHP commandline version switcher" | |
echo "Switching to $php_version" | |
# Unlink php version | |
brew unlink php@$running_php >/dev/null 2>&1 | |
# Link requested version | |
brew link --overwrite --force "$php_version" >/dev/null 2>&1 | |
echo "" | |
php -v | |
echo "" | |
echo "All done!" | |
else | |
echo "Sorry, but $php_version is not installed via brew. Install by running: brew install $php_version" | |
fi | |
else | |
echo "Unknown version of PHP. PHP Switcher can only handle arguments of:" ${brew_array[@]} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment