Last active
January 12, 2022 19:31
-
-
Save sh6210/63bc009c40706f6e53b4868631ee183c to your computer and use it in GitHub Desktop.
Bash script for switching php version.
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
REQUESTED_VERSION=${1?Error: no version given} | |
CURRENT_VERSION=$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;') | |
echo Current Version: $CURRENT_VERSION | |
echo Requested Version: $REQUESTED_VERSION | |
sudo a2dismod php"$CURRENT_VERSION" \ | |
&& sudo a2enmod php"$REQUESTED_VERSION" \ | |
&& sudo update-alternatives --set php /usr/bin/php"$REQUESTED_VERSION" \ | |
&& sudo service apache2 restart | |
CURRENT_VERSION=$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;') | |
echo done, your PHP Version is: $CURRENT_VERSION |
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
This script accept one argument, the expected php version. | |
In my case, i've placed this bash script under my home directory and made alias | |
> alias bash_file_location_which_change_php_version="/home/devnet/mine/bash/change_php_version.sh" | |
> alias php56="bash_file_location_which_change_php_version 5.6" | |
> alias php74="bash_file_location_which_change_php_version 7.4" | |
> alias php8="bash_file_location_which_change_php_version 8.0" | |
#### If i want to change the php version, all i need to do press php56 or php74 or php8 and i'm done. | |
![switching_php_version_image](https://raw.githubusercontent.com/sh6210/git-image/master/Others/switching_php_version.gif) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment