Skip to content

Instantly share code, notes, and snippets.

@RoboSparrow
Last active July 17, 2017 05:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RoboSparrow/7749e3b9b42da1a2c8ca4326046c7ebd to your computer and use it in GitHub Desktop.
Save RoboSparrow/7749e3b9b42da1a2c8ca4326046c7ebd to your computer and use it in GitHub Desktop.
helper script for switching PHP versions
#!/bin/bash
###
# Script for switching PHP versions
# Ubuntu 16.x dual php install.
# Instructions on how to set this up: http://robosparrow.github.io/2016/12/10/php-5-on-ubuntu16.html
###
GREEN="$(tput setaf 2)"
RED="$(tput setaf 1)"
RESET="$(tput sgr0)"
VERSION="$(php --version | head -n 1 | cut -d " " -f 2 | cut -c 1,3)"
if [ $VERSION = 56 ]
then
#switch to php 7.1.x
echo "${GREEN}Switching to PHP 7.1.x...${RESET}"
sudo a2dismod php5.6 && sudo a2enmod php7.1 && sudo update-alternatives --set php /usr/bin/php7.1 && sudo service apache2 restart && echo "${GREEN}$(php --version | head -n 1)${RESET}"
elif [ $VERSION = 71 ]
then
#switch to php 5.6.x
echo "${GREEN}Switching to PHP 5.6.x ...${RESET}"
sudo a2dismod php7.1 && sudo a2enmod php5.6 && sudo update-alternatives --set php /usr/bin/php5.6 && sudo service apache2 restart && echo "${GREEN}$(php --version | head -n 1)${RESET}"
else
echo "${RED}Version not recognised${RESET}: ${VERSION}, found: $(php --version)"
exit
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment