Small script to display dialog to switch between PHP version.
#!/usr/bin/env bash | |
# | |
# Small script to display dialog to switch between PHP verion. | |
# Tested on Ubuntu 16.04 LTS | |
# | |
# Execution: | |
# $ sudo ./phpswitch.sh | |
# | |
# You can also create a softlink to the /usr/bin directory | |
# $ sudo ln -s ~/phpswitcher.sh /usr/bin/phpswitch | |
# $ sudo phpswitch | |
if [ ! -f /usr/bin/dialog ]; then | |
echo "dialog is required please install it with:" | |
echo " sudo apt install -y dialog" | |
exit -1 | |
fi | |
default=`/usr/bin/php -v` | |
current=${default:4:3} | |
versions=("5.4" "5.5" "5.6" "7.0" "7.1" "7.2" "7.3") | |
options=() | |
for index in ${!versions[@]}; do | |
if [ -f /usr/bin/php${versions[$index]} ]; then | |
options+=($index) | |
options+=(${versions[$index]}) | |
if [ ${versions[$index]} == $current ]; then | |
options+=(on) | |
else | |
options+=(off) | |
fi | |
fi | |
done | |
selected=$(dialog --backtitle "Available PHP versions:" \ | |
--radiolist "Select version:" 0 0 0 \ | |
"${options[@]}" 2>&1 >/dev/tty) | |
clear | |
for version in ${versions[@]}; do | |
if [ -f /etc/apache2/mods-available/php${version}.conf ] && [ -f /etc/apache2/mods-available/php${version}.load ]; then | |
a2dismod php${version} | |
fi | |
done | |
echo "Switching php binary..." | |
update-alternatives --set php /usr/bin/php${versions[$selected]} | |
echo "done!" | |
echo "Switching php Apache2 handler..." | |
a2enmod php${versions[$selected]} | |
echo "done!" | |
echo "Rebooting Apache2" | |
service apache2 restart | |
echo "done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment