-
-
Save ruden/8df5b607927a47665471c19be0d9dcfb to your computer and use it in GitHub Desktop.
My switch php versions
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 | |
array_contains () { | |
local array="$1[@]" | |
local seeking=$2 | |
local in=1 | |
for element in "${!array}"; do | |
if [[ $element == $seeking ]]; then | |
in=0 | |
break | |
fi | |
done | |
return $in | |
} | |
declare -a versions; update-alternatives --list php | while read version; do versions+=${version: -3}; done | |
versions=($(update-alternatives --list php | while read version; do echo -n ${version: -3}; echo -n " "; done; echo)) | |
#echo $versions | |
if [ ${#versions[@]} -eq 0 ]; then | |
echo -n "Could not get versions from update-alternatives - using default versions: " | |
versions=(5.6 7.0 7.1) | |
else | |
echo -n "Found the following available php-versions: " | |
fi | |
echo ${versions[*]} | |
if array_contains versions $1; then | |
(sudo a2dismod php7.1 | |
sudo a2dismod php7.0 | |
sudo a2dismod php5.6 | |
sudo a2enmod php$1 | |
sudo service apache2 restart | |
sudo ln -sfn /usr/bin/php$1 /etc/alternatives/php) >& /dev/null | |
echo "Start $(php -v | head -1)" | |
else | |
echo "Version not supported" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment