-
Notifications
You must be signed in to change notification settings - Fork 0
/
togglephp
executable file
·52 lines (46 loc) · 1.34 KB
/
togglephp
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
#!/bin/bash
systemctl stop nginx && systemctl start apache2
activate_php() {
local php_version=$1
if [ "$php_version" = "7.0" ] || [ "$php_version" = "7.3" ] || [ "$php_version" = "7.4" ] || [ "$php_version" = "8.0" ] || [ "$php_version" = "$php_version" ] || [ "$php_version" = "8.2" ]; then
sudo update-alternatives --set php "/usr/bin/php$php_version"
sudo a2dismod php* && sudo a2enmod "php$php_version" && sudo systemctl restart apache2
echo "PHP Version $php_version activated"
else
echo "Invalid PHP version: $php_version"
exit 1
fi
}
install_php() {
local php_version=$1
sudo apt-get install -y \
"php$php_version" \
"libapache2-mod-php$php_version" \
"php$php_version-cli" \
"php$php_version-common" \
"php$php_version-mysql" \
"php$php_version-zip" \
"php$php_version-gd" \
"php$php_version-mbstring" \
"php$php_version-curl" \
"php$php_version-xml" \
"php$php_version-bcmath" \
"libapache2-mod-php$php_version"
}
while getopts 'v:i' flag; do
case "${flag}" in
v)
activate_php "${OPTARG}"
exit 0
;;
i)
install_php "${OPTARG}"
exit 0
;;
*)
echo "Invalid option or missing argument"
exit 1
;;
esac
done
exit 0