Last active
January 18, 2019 21:39
-
-
Save KatarinaT/2ac77bd9fd654db046a8a926d2b8c9e5 to your computer and use it in GitHub Desktop.
Shell 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
#!/bin/bash | |
## Switch php version | |
## Command line need only one argument, it's php version | |
exists() | |
{ | |
command -v "$1" >/dev/null 2>&1 | |
} | |
##< Allowed only for admin | |
if ! [ $(id -u) = 0 ]; then | |
echo "The script need to be run as root." >&2 | |
exit 1 | |
fi | |
##< Check existing parameters | |
if [ $# -gt 0 ]; then | |
if exists "php$1"; then | |
echo 'This version php exists!' | |
echo "Starting switching to php$1..." | |
##< Unlinking the old PHP version | |
if [ -f /usr/bin/php ]; then | |
unlink /usr/bin/php | |
fi; | |
unlink /etc/alternatives/php | |
##< Linking new PHP version | |
ln -s /usr/bin/php$1 /etc/alternatives/php | |
if ! [ -f /usr/bin/php ]; then | |
ln -s /etc/alternatives/php /usr/bin/php | |
fi; | |
echo "PHP version have switched:" | |
php -v | |
exit 0 | |
else | |
echo 'Your system does not have this php version. Firstly install it...' | |
fi | |
else | |
echo "Your command line contains no arguments, specify version of php..." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment