Skip to content

Instantly share code, notes, and snippets.

@jfreites
Last active February 20, 2020 16:04
Show Gist options
  • Save jfreites/791f5c43ecdc73fe8c76 to your computer and use it in GitHub Desktop.
Save jfreites/791f5c43ecdc73fe8c76 to your computer and use it in GitHub Desktop.
Multiple PHP Versions
#!/bin/bash
# @author OSOM-IT
echo " php switcher "
version=$1
if [[ "70" -ne version && "56" -ne version && "0" -ne version ]]
then
echo "You must specify php version (70, 56)"
exit 1 else
if [[ "0" -ne version ]]
then
echo "> Preparing to load php $version"
fi
fi
function unload_php {
echo "> Unloading current php version"
brew unlink php70 > /dev/null
brew unlink php56 > /dev/null
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.php70.plist 2> /dev/null
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist 2> /dev/null
}
function load_php {
echo "> Loading desired php version"
brew link php$1 > /dev/null
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php$1.plist
sed -i '' 's;^PHP_HOME=.*;PHP_HOME='"$(brew --prefix homebrew/php/php$1)/bin"';' ~/.bash_profile
source ~/.bash_profile
echo "> "`php -v | head -n 1`" Loaded"
}
unload_php
if [[ "0" -ne version ]]
then
load_php $version
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment