-
-
Save max107/8de98c80c1a084838596aeb2934a114b to your computer and use it in GitHub Desktop.
sphp for 7.0 without apache
This file contains hidden or 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 | |
# Creator: Phil Cook | |
# Modified: Andy Miller, Maxim Falaleev | |
brew_prefix=$(brew --prefix | sed 's#/#\\\/#g') | |
brew_array=("7.0","7.1","7.2", "7.3") | |
php_array=("[email protected]" "[email protected]" "[email protected]" "[email protected]") | |
valet_support_php_version_array=("[email protected]" "[email protected]" "[email protected]" "[email protected]") | |
php_installed_array=() | |
php_version="php@$1" | |
php_opt_path="$brew_prefix\/opt\/" | |
php_module="$php7_module" | |
# Has the user submitted a version required | |
if [[ -z "$1" ]] | |
then | |
echo "usage: sphp version [-s|-s=*] [-c=*]"; echo; | |
echo " version one of:" ${brew_array[@]}; | |
echo " -s skip change of mod_php on apache"; | |
echo " -s=* skip change of mod_php on apache or valet restart i.e (apache|valet,apache|valet)"; | |
echo " -c=* switch a specific config (apache|valet,apache|valet"; echo; | |
exit | |
fi | |
# What versions of php are installed via brew | |
for i in ${php_array[*]} | |
do | |
if [[ -n "$(brew ls --versions "$i")" ]] | |
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 | |
# Stop valet service | |
if [[ ($valet_installed -eq 1) && ($valet_restart -eq 1) ]]; then | |
echo "Stop Valet service"; | |
valet stop; | |
fi | |
# Switch Shell | |
echo "Switching to $php_version" | |
echo "Switching your shell" | |
for i in ${php_installed_array[@]} | |
do | |
if [[ -n $(brew ls --versions $i) ]] | |
then | |
brew unlink $i | |
fi | |
done | |
brew link --force "$php_version" | |
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