Skip to content

Commit 9ae4cc5

Browse files
committed
Add upgrade procedure from webtpl multiphp to multi php-fpm backend
ngx+fpm is supported by default, ngx+mphp and apache+mphp are migrated, apache with internal php is skipped
1 parent eeb9926 commit 9ae4cc5

File tree

8 files changed

+143
-13
lines changed

8 files changed

+143
-13
lines changed

bin/v-add-web-domain-backend

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ cat $WEBTPL/$WEB_BACKEND/$template.tpl |\
6363
-e "s|%user%|$user|g"\
6464
-e "s|%domain%|$domain|g"\
6565
-e "s|%backend%|$backend_type|g"\
66-
-e "s|%backend_version%|$version|g" > $pool/$backend_type.conf
66+
-e "s|%backend_version%|$backend_version|g" > $pool/$backend_type.conf
6767

6868

6969
#----------------------------------------------------------#

bin/v-add-web-php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if [[ ! $version =~ ^[0-9]\.[0-9]+ ]]; then
3333
fi
3434

3535
# Check if php version already exists
36-
if [ -f "$php_fpm" ] && [ -f "$HESTIA/data/templates/$WEB_SYSTEM/PHP-$version.sh" ]; then
36+
if [ -f "$php_fpm" ] && [ -f "$HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl" ]; then
3737
echo "Version already installed..."
3838
exit
3939
fi
@@ -100,7 +100,7 @@ cp -f $HESTIA_INSTALL_DIR/php-fpm/dummy.conf /etc/php/$version/fpm/pool.d/
100100
sed -i "s/9999/99$v_tpl/g" /etc/php/$version/fpm/pool.d/dummy.conf
101101

102102
# Install backend template
103-
cp -f $HESTIA_INSTALL_DIR/multiphp/php-fpm/default.tpl \
103+
cp -f $HESTIA_INSTALL_DIR/php-fpm/multiphp.tpl \
104104
$HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl
105105

106106
#----------------------------------------------------------#

bin/v-change-web-domain-backend-tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ cat $WEBTPL/$WEB_BACKEND/$template.tpl |\
7070
-e "s|%domain%|$domain|g"\
7171
-e "s|%domain_idn%|$domain_idn|"\
7272
-e "s|%backend%|$backend_type|g"\
73-
-e "s|%backend_version%|$version|g" > $pool/$backend_type.conf
73+
-e "s|%backend_version%|$backend_version|g" > $pool/$backend_type.conf
7474

7575
# Checking backend pool configuration
7676
if [ "$backend_type" = "$user" ]; then

bin/v-delete-web-php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ if [ -f "$php_fpm" ]; then
7575
echo "apt-get purge $mph"
7676
fi
7777

78-
# Remove php templates
78+
# Remove backend template
7979
rm -f $HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl
8080

8181
#----------------------------------------------------------#

bin/v-update-web-templates

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ if [ -d "${WEBTPL}" ]; then
2727
rm -rf "${WEBTPL}/unassigned" 2>/dev/null
2828
fi
2929

30+
for php_ver in $(ls /etc/php/); do
31+
[ ! -d "/etc/php/$php_ver/fpm/pool.d/" ] && continue
32+
cp -f "$HESTIA_INSTALL_DIR/php-fpm/multiphp.tpl" ${WEBTPL}/php-fpm/PHP-${php_ver/\./_}.tpl
33+
done
34+
3035
for webtpl_folder in $(ls $HESTIA_INSTALL_DIR/templates/web/* -d 2>/dev/null | egrep -v '/(nginx)$' ); do
3136
cp -rf "${webtpl_folder}" "${WEBTPL}/"
3237
done
@@ -35,7 +40,7 @@ done
3540

3641
# Update Multi-PHP templates
3742
php_versions=$(ls /etc/php/*/fpm -d 2>/dev/null | wc -l)
38-
if [ "$php_versions" -gt 1 ]; then
43+
if [ "$php_versions" -gt 1 ] && [ -z "$WEB_BACKEND" ]; then
3944
for v in $(ls /etc/php/); do
4045
if [ ! -d "/etc/php/$v/fpm/pool.d/" ]; then
4146
continue
@@ -53,7 +58,7 @@ if [ "$php_versions" -gt 1 ]; then
5358
fi
5459
fi
5560

56-
if [ "$PROXY_SYSTEM" = 'nginx' ] || [ "$php_versions" -le 1 ]; then
61+
if [ "$PROXY_SYSTEM" = 'nginx' ] || [ "$WEB_BACKEND" = "php-fpm" ]; then
5762
cp -rf "${HESTIA_INSTALL_DIR}/templates/web/nginx" "${WEBTPL}/"
5863
fi
5964

func/domain.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,22 @@ is_web_alias_new() {
8484

8585
# Prepare web backend
8686
prepare_web_backend() {
87+
pool=$(find -L /etc/php/ -name "$domain.conf" -exec dirname {} \;)
8788
# Check if multiple-PHP installed
8889
regex="socket-(\d+)_(\d+)"
8990
if [[ $template =~ ^PHP-([0-9])\_([0-9])$ ]]; then
90-
version="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"
91-
pool=$(find -L /etc/php/$version -type d \( -name "pool.d" -o -name "*fpm.d" \))
91+
backend_version="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"
92+
pool=$(find -L /etc/php/$backend_version -type d \( -name "pool.d" -o -name "*fpm.d" \))
9293
else
93-
version=$(php -r "echo (float)phpversion();")
94-
pool=$(find -L /etc/php/$version -type d \( -name "pool.d" -o -name "*fpm.d" \))
94+
if [ -z "$pool" ] || [ -z "$BACKEND" ]; then
95+
backend_version=$(php -r "echo (float)phpversion();")
96+
pool=$(find -L /etc/php/$backend_version -type d \( -name "pool.d" -o -name "*fpm.d" \))
97+
fi
9598
fi
9699

97100
if [ ! -e "$pool" ]; then
98101
check_result $E_NOTEXIST "php-fpm pool doesn't exist"
99102
fi
100-
101103
backend_type="$domain"
102104
if [ "$WEB_BACKEND_POOL" = 'user' ]; then
103105
backend_type="$user"

install/upgrade/versions/latest.sh

Lines changed: 124 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,127 @@ fi
5454
# Remove errornous history.log file created by certain builds due to bug in v-restart-system
5555
if [ -e $HESTIA/data/users/history.log ]; then
5656
rm -f $HESTIA/data/users/history.log
57-
fi
57+
fi
58+
59+
#
60+
# Migrate legacy multiphp to full php-fpm backend
61+
#
62+
# nginx+fpm (default)
63+
# nothing to be done here,
64+
# (Adding new php backends will make them available on edit/web)
65+
#
66+
# nginx+multiphp,
67+
# nginx+apache+multiphp,
68+
# apache+multiphp:
69+
# Change Hestia WEB_BACKEND from null to php-fpm
70+
# Create backend templates ex: PHP-7_3, PHP-5_6 (in $HESTIA/data/templates/web/php-fpm/)
71+
# v-update-web-templates
72+
# Loop trough all web domains
73+
# If official multiphp tpl is used ex: PHP-72, then change backend tpl and set app web template to default
74+
# ( old default.tpl backend maps to PHP-7_3 )
75+
# If not, parse php version from tpl file , fallback to latest version,
76+
# Copy all non-official tpls to php-fpm folder (as app web template includin bash script if present)
77+
#
78+
# a2 (non-fpm) or nginx+a2(non-fpm)
79+
# - Skipped
80+
#
81+
82+
DEFAULT_BTPL="PHP-7_3"
83+
num_php_versions=$(ls -d /etc/php/*/fpm/pool.d 2>/dev/null |wc -l)
84+
echo $num_php_versions
85+
86+
if [ "$num_php_versions" -gt 1 ] && [ -z "$WEB_BACKEND" ]; then
87+
# Legacy multiphp
88+
89+
echo $num_php_versions
90+
sed -i "/^WEB_BACKEND=/d" $HESTIA/conf/hestia.conf
91+
echo "WEB_BACKEND='php-fpm'" >> $HESTIA/conf/hestia.conf
92+
93+
for php_ver in $(ls /etc/php/); do
94+
[ ! -d "/etc/php/$php_ver/fpm/pool.d/" ] && continue
95+
cp -f "$HESTIA_INSTALL_DIR/php-fpm/multiphp.tpl" ${WEBTPL}/php-fpm/PHP-${php_ver/\./_}.tpl
96+
done
97+
98+
if [ "$WEB_SYSTEM" = 'nginx' ] ]; then
99+
cp -rf "${HESTIA_INSTALL_DIR}/templates/web/nginx" "${WEBTPL}/"
100+
fi
101+
102+
# Migrate domains
103+
for user in $($BIN/v-list-sys-users plain); do
104+
echo "Migrating legacy multiphp domains for user: $user"
105+
for domain in $($BIN/v-list-web-domains $user plain |cut -f1); do
106+
echo "Processing domain: $domain"
107+
web_tpl="default"
108+
backend_tpl="$DEFAULT_BTPL"
109+
domain_tpl=$($BIN/v-list-web-domain $user $domain |grep "^TEMPLATE:" |awk '{print $2;}' );
110+
111+
if [ "$domain_tpl" = "PHP-56" ]; then
112+
backend_tpl="PHP-5_6"
113+
elif [ "$domain_tpl" = "PHP-70" ]; then
114+
backend_tpl="PHP-7_0"
115+
elif [ "$domain_tpl" = "PHP-71" ]; then
116+
backend_tpl="PHP-7_1"
117+
elif [ "$domain_tpl" = "PHP-72" ]; then
118+
backend_tpl="PHP-7_2"
119+
elif [ "$domain_tpl" = "PHP-73" ] || [ "$domain_tpl" = "default" ] || [ -z "$domain_tpl" ]; then
120+
backend_tpl="PHP-7_3"
121+
else
122+
# Custom domain template used
123+
echo "Domain is using a custom multiphp template (or non-multiphp one)"
124+
125+
web_tpl="$domain_tpl"
126+
if [ -f "${WEBTPL}/$WEB_SYSTEM/php-fpm/$web_tpl.tpl" ]; then
127+
# php-fpm backend folder allready has a template with the same name
128+
web_tpl="custom-$domain_tpl"
129+
fi
130+
131+
# Copy custom template to php-fpm backend folder
132+
mkdir -p "$WEBTPL/$WEB_SYSTEM/php-fpm"
133+
if [ -f "$WEBTPL/$WEB_SYSTEM/$domain_tpl.sh" ]; then
134+
cp "$WEBTPL/$WEB_SYSTEM/$domain_tpl.sh" "$WEBTPL/$WEB_SYSTEM/php-fpm/$web_tpl.sh"
135+
fi
136+
cp "$WEBTPL/$WEB_SYSTEM/$domain_tpl.tpl" "$WEBTPL/$WEB_SYSTEM/php-fpm/$web_tpl.tpl"
137+
cp "$WEBTPL/$WEB_SYSTEM/$domain_tpl.stpl" "$WEBTPL/$WEB_SYSTEM/php-fpm/$web_tpl.stpl"
138+
139+
140+
if [[ $(grep "unix:/" $WEBTPL/$WEB_SYSTEM/$domain_tpl.tpl |egrep -v "^\s*#" |tail -n1) \
141+
=~ unix:\/run\/php\/php([0-9]+\.[0-9]+)-fpm.+\.sock ]]; then
142+
143+
# Found a custom template that is based on official multiphp one
144+
backend_tpl="PHP-${BASH_REMATCH[1]/\./_}"
145+
echo "Custom multiphp template ($domain_tpl) compatible with backend: $backend_tpl"
146+
147+
# Remove multiphp switching script
148+
rm -f "$WEBTPL/$WEB_SYSTEM/php-fpm/$web_tpl.sh"
149+
150+
# Replace hardcoded php-fpm socket path with tpl variable, ignoring commented lines
151+
sed '/^[[:space:]]*#/!s/unix:.*;/%backend_lsnr%;/g' "$WEBTPL/$WEB_SYSTEM/php-fpm/$web_tpl.tpl"
152+
sed '/^[[:space:]]*#/!s/unix:.*;/%backend_lsnr%;/g' "$WEBTPL/$WEB_SYSTEM/php-fpm/$web_tpl.stpl"
153+
fi
154+
fi
155+
156+
echo "Parsed config: oldTPL=$domain_tpl newTPL:$web_tpl newBackTPL:$backend_tpl"
157+
$BIN/v-change-web-domain-tpl "$user" "$domain" "$web_tpl" "no"
158+
$BIN/v-change-web-domain-backend-tpl "$user" "$domain" "$backend_tpl" "no"
159+
echo -e "--done--\n"
160+
done
161+
done
162+
163+
# cleanup legacy multiphp templates
164+
for php_ver in $(ls /etc/php/); do
165+
[ ! -d "/etc/php/$php_ver/fpm/pool.d/" ] && continue
166+
echo "Remove legacy multiphp templates for: $php_ver"
167+
[ -f "$WEBTPL/$WEB_SYSTEM/PHP-${php_ver//.}.sh" ] && rm "$WEBTPL/$WEB_SYSTEM/PHP-${php_ver//.}.sh"
168+
[ -f "$WEBTPL/$WEB_SYSTEM/PHP-${php_ver//.}.tpl" ] && rm "$WEBTPL/$WEB_SYSTEM/PHP-${php_ver//.}.tpl"
169+
[ -f "$WEBTPL/$WEB_SYSTEM/PHP-${php_ver//.}.stpl" ] && rm "$WEBTPL/$WEB_SYSTEM/PHP-${php_ver//.}.stpl"
170+
done
171+
172+
# Remove default symlinks
173+
[ -f "$WEBTPL/$WEB_SYSTEM/default.sh" ] && rm "$WEBTPL/$WEB_SYSTEM/default.sh"
174+
[ -f "$WEBTPL/$WEB_SYSTEM/default.tpl" ] && rm "$WEBTPL/$WEB_SYSTEM/default.tpl"
175+
[ -f "$WEBTPL/$WEB_SYSTEM/default.stpl" ] && rm "$WEBTPL/$WEB_SYSTEM/default.stpl"
176+
177+
178+
$BIN/v-update-web-templates 'no'
179+
fi
180+

0 commit comments

Comments
 (0)