Skip to content

Commit 2a4353f

Browse files
[core] Move install_php() from VED to main (#5182)
1 parent d21cbf1 commit 2a4353f

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

misc/tools.func

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -380,45 +380,44 @@ install_php() {
380380
# Deduplicate modules
381381
COMBINED_MODULES=$(echo "$COMBINED_MODULES" | tr ',' '\n' | awk '!seen[$0]++' | paste -sd, -)
382382

383-
local CURRENT_PHP
383+
local CURRENT_PHP=""
384384
if command -v php >/dev/null 2>&1; then
385385
CURRENT_PHP=$(php -v 2>/dev/null | awk '/^PHP/{print $2}' | cut -d. -f1,2)
386-
else
387-
CURRENT_PHP=""
388386
fi
389387

390388
if [[ -z "$CURRENT_PHP" ]]; then
391-
msg_info "Setup PHP $PHP_VERSION"
389+
msg_info "No PHP found, setting up PHP $PHP_VERSION"
392390
elif [[ "$CURRENT_PHP" != "$PHP_VERSION" ]]; then
393391
msg_info "PHP $CURRENT_PHP detected, migrating to PHP $PHP_VERSION"
394-
if [[ ! -f /etc/apt/sources.list.d/php.list ]]; then
395-
$STD curl -fsSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb
396-
$STD dpkg -i /tmp/debsuryorg-archive-keyring.deb
397-
echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ ${DISTRO_CODENAME} main" \
398-
>/etc/apt/sources.list.d/php.list
399-
$STD apt-get update
400-
fi
401-
402392
$STD apt-get purge -y "php${CURRENT_PHP//./}"* || true
403393
fi
404394

395+
# Ensure Sury repo is available
396+
if [[ ! -f /etc/apt/sources.list.d/php.list ]]; then
397+
$STD curl -fsSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb
398+
$STD dpkg -i /tmp/debsuryorg-archive-keyring.deb
399+
echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ ${DISTRO_CODENAME} main" \
400+
>/etc/apt/sources.list.d/php.list
401+
$STD apt-get update
402+
fi
403+
405404
local MODULE_LIST="php${PHP_VERSION}"
406405
IFS=',' read -ra MODULES <<<"$COMBINED_MODULES"
407406
for mod in "${MODULES[@]}"; do
408407
MODULE_LIST+=" php${PHP_VERSION}-${mod}"
409408
done
409+
410410
if [[ "$PHP_FPM" == "YES" ]]; then
411411
MODULE_LIST+=" php${PHP_VERSION}-fpm"
412412
fi
413413

414-
if [[ "$PHP_APACHE" == "YES" ]]; then
415-
# Optionally disable old Apache PHP module
414+
if [[ "$PHP_APACHE" == "YES" ]] && [[ -n "$CURRENT_PHP" ]]; then
416415
if [[ -f /etc/apache2/mods-enabled/php${CURRENT_PHP}.load ]]; then
417416
$STD a2dismod php${CURRENT_PHP} || true
418417
fi
419418
fi
420419

421-
if [[ "$PHP_FPM" == "YES" ]]; then
420+
if [[ "$PHP_FPM" == "YES" ]] && [[ -n "$CURRENT_PHP" ]]; then
422421
$STD systemctl stop php${CURRENT_PHP}-fpm || true
423422
$STD systemctl disable php${CURRENT_PHP}-fpm || true
424423
fi
@@ -436,8 +435,7 @@ install_php() {
436435
fi
437436

438437
# Patch all relevant php.ini files
439-
local PHP_INI_PATHS=()
440-
PHP_INI_PATHS+=("/etc/php/${PHP_VERSION}/cli/php.ini")
438+
local PHP_INI_PATHS=("/etc/php/${PHP_VERSION}/cli/php.ini")
441439
[[ "$PHP_FPM" == "YES" ]] && PHP_INI_PATHS+=("/etc/php/${PHP_VERSION}/fpm/php.ini")
442440
[[ "$PHP_APACHE" == "YES" ]] && PHP_INI_PATHS+=("/etc/php/${PHP_VERSION}/apache2/php.ini")
443441

@@ -452,7 +450,6 @@ install_php() {
452450
fi
453451
done
454452
}
455-
456453
# ------------------------------------------------------------------------------
457454
# Installs or updates Composer globally.
458455
#

0 commit comments

Comments
 (0)