Last active
July 21, 2023 09:14
-
-
Save qadirpervez/0a6e256dd857ccb5eba7a4b657a70fce to your computer and use it in GitHub Desktop.
change php version in cli and for apache
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
## Switch php version php-cli and in apache | |
echo | |
echo -e "\033[1;31m PHP Version changer Switcher\e[0m" | |
echo | |
echo -e "\033[0;33m PHP version currently active in your '/cli': \033[0;35m`sudo php -v | head -n 1 | cut -c 1-10` \e[0m" # Checking running php version | |
sudo sudo service apache2 stop &>- # Stopping lampp stack if running | |
echo | |
echo -e "\033[0;31m versions that you have installed:\e[0m" | |
ls -ldt /etc/php/* | awk '{print $9}' | |
echo | |
## Taking inputs | |
echo -e "\033[0;34m Write the PHP version currently active \033[1;31m(be careful)" | |
echo -e "\033[0;34m Please check the text in the \033[0;35mpurple\033[0;34m and" | |
echo -en " write eg. 7.2 for PHP 7.2.34: \e[0m" | |
read RUNVERSION | |
echo "$RUNVERSION"; | |
if [ -z "$1" ] ; then | |
echo -e "\033[0;34m" | |
echo "Write the PHP version you want to switch: " | |
echo "[7.2] for PHP 7.2" | |
echo "[7.4] for PHP 7.4" | |
echo "[8.0] for PHP 8.0" | |
echo -e "\e[0m" | |
read REQVERSION | |
else | |
REQVERSION=$1 | |
fi | |
echo "Version: " $REQVERSION | |
echo | |
## changing versions | |
sudo a2dismod php$RUNVERSION | |
sudo a2enmod php$REQVERSION && sudo update-alternatives --set php /usr/bin/php$REQVERSION | |
sudo service apache2 restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment