Skip to content

Instantly share code, notes, and snippets.

@Maurisss94
Created March 5, 2020 09:19
Show Gist options
  • Save Maurisss94/3c579ee8d68a44be2400ff1fc7bc1f10 to your computer and use it in GitHub Desktop.
Save Maurisss94/3c579ee8d68a44be2400ff1fc7bc1f10 to your computer and use it in GitHub Desktop.
Script to change rapidly the php version, from x version to y version
#!/bin/bash
showHelp() {
echo ""
echo Missing parameters, Needs two parameters -f --from PHP version, and -t --to PHP version
echo -e '\t' Example:
echo -e '\t' $0 -f 5.6 -t 7.3
exit 1
}
isNumber(){
re='^[0-9]+([.][0-9]+)?$'
if ! [[ $parameterFrom =~ $re ]] && [[ $parameterTo =~ $re ]] ; then
echo "error: Not a number" >&2; exit 1
fi
}
while getopts "f:t:" opt
do
case "$opt" in
f ) parameterFrom="$OPTARG" ;;
t ) parameterTo="$OPTARG" ;;
? ) showHelp ;;
esac
done
isNumber
sudo a2dismod php$parameterFrom && sudo a2enmod php$parameterTo && sudo service apache2 restart &&
sudo update-alternatives --set php /usr/bin/php$parameterTo && sudo update-alternatives --set phar /usr/bin/phar$parameterTo &&
sudo update-alternatives --set phar.phar /usr/bin/phar.phar$parameterTo && sudo update-alternatives --set phpize /usr/bin/phpize$parameterTo &&
sudo update-alternatives --set php-config /usr/bin/php-config$parameterTo
echo DONE!
echo ""
php -v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment