Skip to content

Instantly share code, notes, and snippets.

@marceloxp marceloxp/php-alternate.sh
Last active Feb 18, 2019

Embed
What would you like to do?
Change PHP Versions
#!/bin/bash
# chmod +x ~/dev/php-alternate.sh
main()
{
echo "---------------------------------------------------------------------------------------------------"
echo "CURRENT PHP VERSION"
echo "---------------------------------------------------------------------------------------------------"
php -v
echo "---------------------------------------------------------------------------------------------------"
echo "Choose a PHP version:"
echo "--------------------"
echo "56 - Activate PHP 5.6"
echo "70 - Activate PHP 7.0"
echo "71 - Activate PHP 7.1"
echo "72 - Activate PHP 7.2"
echo "--------------------"
echo "9 - Cancel"
echo ""
read opcao;
case $opcao in
"56")
title "PHP 5.6 selected"
php56
;;
"70")
title "PHP 7.0 selected"
php70
;;
"71")
title "PHP 7.1 selected"
php71
;;
"72")
title "PHP 7.2 selected"
php72
;;
"9")
exit 0
;;
esac
restartapache
showphpversion
read -p "Press any key to continue... " -n1 -s
echo ""
echo ""
}
showphpversion()
{
title "Show PHP Version"
php -v
echo ""
}
restartapache()
{
title "Restarting Apache..."
sudo systemctl restart apache2
echo ""
}
sudopassword()
{
read -s -p "Enter Password for sudo: " sudoPW
echo $sudoPW | sudo -S su
echo ""
}
title()
{
echo "-------------------------------------------------------"
echo $1
echo "-------------------------------------------------------"
}
php56()
{
echo ""
sudopassword
title "Activating PHP 5.6"
sudo update-alternatives --set php /usr/bin/php5.6
sudo a2dismod php7.0
sudo a2dismod php7.1
sudo a2dismod php7.2
sudo a2enmod php5.6
cd /etc/apache2/sites-available/
sudo a2dissite *php70*
sudo a2dissite *php71*
sudo a2dissite *php72*
sudo a2ensite *php56*
sudo a2enmod rewrite
}
php70()
{
echo ""
sudopassword
title "Activating PHP 7.0"
sudo update-alternatives --set php /usr/bin/php7.0
sudo a2dismod php5.6
sudo a2dismod php7.1
sudo a2dismod php7.2
sudo a2enmod php7.0
cd /etc/apache2/sites-available/
sudo a2dissite *php56*
sudo a2dissite *php71*
sudo a2dissite *php72*
sudo a2ensite *php70*
sudo a2enmod rewrite
}
php71()
{
echo ""
sudopassword
title "Activating PHP 7.1"
sudo update-alternatives --set php /usr/bin/php7.1
sudo a2dismod php5.6
sudo a2dismod php7.0
sudo a2dismod php7.2
sudo a2enmod php7.1
cd /etc/apache2/sites-available/
sudo a2dissite *php56*
sudo a2dissite *php70*
sudo a2dissite *php72*
sudo a2ensite *php71*
sudo a2enmod rewrite
}
php72()
{
echo ""
sudopassword
title "Activating PHP 7.2"
sudo update-alternatives --set php /usr/bin/php7.2
sudo a2dismod php5.6
sudo a2dismod php7.0
sudo a2dismod php7.1
sudo a2enmod php7.2
cd /etc/apache2/sites-available/
sudo a2dissite *php56*
sudo a2dissite *php70*
sudo a2dissite *php71*
sudo a2ensite *php72*
sudo a2enmod rewrite
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.