Created
September 8, 2023 10:22
-
-
Save JunaidQadirB/d07244930671920367d4b3e64ee1be94 to your computer and use it in GitHub Desktop.
Switch PHP Versions
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
#!/bin/bash | |
php_new_version=$1 | |
if [ -z "$php_new_version" ] | |
then | |
echo "Please enter which PHP version do you want to switch to." | |
exit 1 | |
fi | |
php_version=$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;') | |
if [ $php_version == $php_new_version ] | |
then | |
echo "You are already uisng PHP $php_version" | |
exit 1 | |
fi | |
echo "Switching PHP from $php_version to $php_new_version..." | |
echo "" | |
echo "Disabling PHP $php_version..." | |
sudo a2dismod php$php_version | |
echo "Enabling PHP $php_version..." | |
sudo a2enmod php$php_new_version | |
echo "Updating system to use PHP $php_new_version..." | |
sudo update-alternatives --set php /usr/bin/php$php_new_version | |
php -v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Make sure you already install the PHP versions you want to switch between.
Usage:
switchphp [version-number]
To switch to PHP 7.4, type
switchphp 7.4