Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Add Comment
Please, Sign In to add comment