Skip to content

Commit cfd72dd

Browse files
committed
Multiphp: ignore non php-fpm php versions when detecting the default php version
-After the release of php7.4, upgrading a system would partially install some php components but not php-fpm so it would break multiphp instalations for web domains which used the 'default' backend template
1 parent 1c20512 commit cfd72dd

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

func/domain.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ prepare_web_backend() {
9494
backend_version="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"
9595
pool=$(find -L /etc/php/$backend_version -type d \( -name "pool.d" -o -name "*fpm.d" \))
9696
else
97-
backend_version=$(php -r "echo (float)phpversion();")
97+
backend_version=$(multiphp_default_version)
9898
if [ -z "$pool" ] || [ -z "$BACKEND" ]; then
9999
pool=$(find -L /etc/php/$backend_version -type d \( -name "pool.d" -o -name "*fpm.d" \))
100100
fi

func/main.sh

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,15 +1072,33 @@ multiphp_count() {
10721072
}
10731073

10741074
multiphp_versions() {
1075+
local -a php_versions_list;
1076+
local php_ver;
10751077
if [ "$(multiphp_count)" -gt 0 ] ; then
1076-
for php_ver in $(ls /etc/php/); do
1078+
for php_ver in $(ls -v /etc/php/); do
10771079
[ ! -d "/etc/php/$php_ver/fpm/pool.d/" ] && continue
1078-
echo -n "$php_ver "
1080+
php_versions_list+=($php_ver)
10791081
done
1080-
echo -en '\n'
1082+
echo "${php_versions_list[@]}"
10811083
fi
10821084
}
10831085

1086+
multiphp_default_version() {
1087+
# Get system wide default php version (set by update-alternatives)
1088+
local sys_phpversion=$(php -r "echo (float)phpversion();")
1089+
1090+
# Check if the system php also has php-fpm enabled, otherwise return
1091+
# the most recent php version which does have it installed.
1092+
if [ ! -d "/etc/php/$sys_phpversion/fpm/pool.d/" ]; then
1093+
local all_versions="$(multiphp_versions)"
1094+
if [ ! -z "$all_versions" ]; then
1095+
sys_phpversion="${all_versions##*\ }";
1096+
fi
1097+
fi
1098+
1099+
echo "$sys_phpversion"
1100+
}
1101+
10841102
# Run arbitrary cli commands with dropped privileges
10851103
# Note: setpriv --init-groups is not available on debian9 (util-linux 2.29.2)
10861104
# Input:

0 commit comments

Comments
 (0)