-
Notifications
You must be signed in to change notification settings - Fork 0
/
phpbrewswitch
executable file
·88 lines (75 loc) · 1.86 KB
/
phpbrewswitch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
# Usage: bash phpbrewswitch
i=1
c=1
options=()
while [ $c -gt 0 ]
do
v=$(phpbrew list | sed -n "${i}p")
if [ -z "$v" ]; then
c=0
elif [ -n "$v" ]; then
options+=("$v")
fi
i=$[$i+1]
done
count=0
echo ''
echo 'Available versions:'
for i in "${options[@]}"
do
echo "$[$count+1] $i"
count=$[$count+1]
done
echo ''
while true; do
echo 'Which version should be enabled?'
echo 'Just type a number then press enter.'
read selected
if (( $selected > $count )); then
echo "${selected} isn't on the list!"
echo "please type before php version number"
echo ''
else
break
fi;
done
chosen="${options[$selected - 1]}"
chosen="$(echo -e "${chosen}" | tr -d '[:space:]')"
chosen="$(echo -e "${chosen}" | sed 's/\*//g')"
chosen="$(echo -e "${chosen}" | sed 's/php-//g')"
sofile=/usr/lib/apache2/modules/libphp${chosen}.so
conffile5=/etc/apache2/mods-available/php5.load
conffile7=/etc/apache2/mods-available/php7.load
source ~/.phpbrew/bashrc
if [ -f $sofile ]; then
phpbrew switch php-${chosen}
phpbrew list
echo "php-${chosen} to be enabled."
echo 'Need sudo permission for a2dismod/a2enmod/systemctl'
else
echo "${sofile} isn't a file"
fi;
if [[ $chosen =~ ^5 ]]; then
filecontents="LoadModule php5_module $sofile"
conffile=$conffile5
sudo a2dismod php7 -q
sudo a2enmod php5 -q
elif [[ $chosen =~ ^7 ]]; then
filecontents="LoadModule php7_module $sofile"
conffile=$conffile7
sudo a2dismod php5 -q
sudo a2enmod php7 -q
else
echo 'This script only works on php 5 and 7';
exit
fi;
echo $filecontents > $conffile
echo "AddType application/x-httpd-php .php" >> $conffile
echo "Updated $conffile"
sudo systemctl restart apache2
if [[ $? -eq 0 ]]; then
echo 'Restart apache2 success!'
else
echo 'Restart apache2 failure!'
fi;