-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitch-php.sh
More file actions
executable file
·82 lines (72 loc) · 2.69 KB
/
switch-php.sh
File metadata and controls
executable file
·82 lines (72 loc) · 2.69 KB
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
#!/bin/bash
#
# a script to manage different PHP versions on one system
#
# author: Carsten Brandt <mail@cebe.cc>
#
# where are the different php distributions located?
PHPDIR=/srv/php
# function to show usage help
usage(){
echo "usage:"
echo " $0 <buildname> - switch php to <buildname>"
echo " $0 --reset - reset system to use natively installed php version"
echo ""
echo "the following names are available:"
echo ""
ls $PHPDIR
echo ""
echo "you can add a new one by building php with --prefix=$PHPDIR/<buildname>"
}
# no arg shows help
if [ "$1" = "" ] ; then
usage
exit 1
fi
if [ ! "$1" = "--reset" ] ; then
# check if desired php dist is available
if [ ! -d "$PHPDIR/$1" ] ; then
echo "$PHPDIR/$1 does not exist!"
echo ""
usage
exit 1
fi
fi
echo "removing existing alternatives..."
for p in $(update-alternatives --list php | grep "$PHPDIR") ; do
update-alternatives --remove php $p
done
for p in $(update-alternatives --list phpize | grep "$PHPDIR") ; do
update-alternatives --remove phpize $p
done
for p in $(update-alternatives --list php-config | grep "$PHPDIR") ; do
update-alternatives --remove php-config $p
done
for p in $(update-alternatives --list php-cgi | grep "$PHPDIR") ; do
update-alternatives --remove php-cgi $p
done
for p in $(update-alternatives --list php-fpm | grep "$PHPDIR") ; do
update-alternatives --remove php-fpm $p
done
echo "done."
if [ ! "$1" = "--reset" ] ; then
echo "switching PHP to $1..."
update-alternatives --install /usr/bin/php php $PHPDIR/$1/bin/php 10 \
--slave /usr/share/man/man1/php.1.gz php.1.gz $PHPDIR/$1/man/man1/php.1
update-alternatives --set php $PHPDIR/$1/bin/php
update-alternatives --install /usr/bin/phpize phpize $PHPDIR/$1/bin/phpize 10 \
--slave /usr/share/man/man1/phpize.1.gz phpize.1.gz $PHPDIR/$1/man/man1/phpize.1
update-alternatives --set phpize $PHPDIR/$1/bin/phpize
update-alternatives --install /usr/bin/php-config php-config $PHPDIR/$1/bin/php-config 10 \
--slave /usr/share/man/man1/php-config.1.gz php-config.1.gz $PHPDIR/$1/man/man1/php-config.1
update-alternatives --set php-config $PHPDIR/$1/bin/php-config
update-alternatives --install /usr/bin/php-cgi php-cgi $PHPDIR/$1/bin/php-cgi 10 \
--slave /usr/share/man/man1/php-cgi.1.gz php-cgi.1.gz $PHPDIR/$1/man/man1/php-cgi.1
update-alternatives --set php-cgi $PHPDIR/$1/bin/php-cgi
if [ -f $PHPDIR/$1/sbin/php-fpm ] ; then
update-alternatives --install /usr/sbin/php-fpm php-fpm $PHPDIR/$1/sbin/php-fpm 10 \
--slave /usr/share/man/man8/php-fpm.8.gz php-fpm.8.gz $PHPDIR/$1/man/man8/php-fpm.8
update-alternatives --set php-fpm $PHPDIR/$1/bin/php-fpm
fi
echo "done."
fi