[core]: tools.func: increase setup_php function (#6141)

* tools.func: increase setup_php function

* better verbose output
This commit is contained in:
CanbiZ 2025-07-22 13:14:09 +02:00 committed by GitHub
parent bce076161e
commit 2848cf6d6b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -396,9 +396,10 @@ function setup_php() {
COMBINED_MODULES="${DEFAULT_MODULES}" COMBINED_MODULES="${DEFAULT_MODULES}"
fi fi
# Deduplicate modules # Deduplicate
COMBINED_MODULES=$(echo "$COMBINED_MODULES" | tr ',' '\n' | awk '!seen[$0]++' | paste -sd, -) COMBINED_MODULES=$(echo "$COMBINED_MODULES" | tr ',' '\n' | awk '!seen[$0]++' | paste -sd, -)
# Get current PHP-CLI version
local CURRENT_PHP="" local CURRENT_PHP=""
if command -v php >/dev/null 2>&1; then if command -v php >/dev/null 2>&1; then
CURRENT_PHP=$(php -v 2>/dev/null | awk '/^PHP/{print $2}' | cut -d. -f1,2) CURRENT_PHP=$(php -v 2>/dev/null | awk '/^PHP/{print $2}' | cut -d. -f1,2)
@ -420,53 +421,43 @@ function setup_php() {
$STD apt-get update $STD apt-get update
fi fi
# Build module list
local MODULE_LIST="php${PHP_VERSION}" local MODULE_LIST="php${PHP_VERSION}"
for pkg in $MODULE_LIST; do
if ! apt-cache show "$pkg" >/dev/null 2>&1; then
msg_error "Package not found: $pkg"
exit 1
fi
done
IFS=',' read -ra MODULES <<<"$COMBINED_MODULES" IFS=',' read -ra MODULES <<<"$COMBINED_MODULES"
for mod in "${MODULES[@]}"; do for mod in "${MODULES[@]}"; do
MODULE_LIST+=" php${PHP_VERSION}-${mod}" if apt-cache show "php${PHP_VERSION}-${mod}" >/dev/null 2>&1; then
MODULE_LIST+=" php${PHP_VERSION}-${mod}"
else
msg_warn "PHP-Module ${mod} for PHP ${PHP_VERSION} not found skipping"
fi
done done
if [[ "$PHP_FPM" == "YES" ]]; then if [[ "$PHP_FPM" == "YES" ]]; then
MODULE_LIST+=" php${PHP_VERSION}-fpm" MODULE_LIST+=" php${PHP_VERSION}-fpm"
fi fi
# install apache2 with PHP support if requested
if [[ "$PHP_APACHE" == "YES" ]]; then if [[ "$PHP_APACHE" == "YES" ]]; then
$STD apt-get install -y apache2 libapache2-mod-php${PHP_VERSION} if ! dpkg -l | grep -q "libapache2-mod-php${PHP_VERSION}"; then
$STD systemctl restart apache2 || true $STD msg_info "Installing Apache with PHP${PHP_VERSION} support"
fi $STD apt-get install -y apache2 libapache2-mod-php"${PHP_VERSION}"
$STD msg_ok "Setup Apache with PHP${PHP_VERSION}"
if [[ "$PHP_APACHE" == "YES" ]] && [[ -n "$CURRENT_PHP" ]]; then
if [[ -f /etc/apache2/mods-enabled/php${CURRENT_PHP}.load ]]; then
$STD a2dismod php${CURRENT_PHP} || true
fi fi
$STD a2enmod php${PHP_VERSION}
$STD systemctl restart apache2 || true
fi fi
if [[ "$PHP_FPM" == "YES" ]] && [[ -n "$CURRENT_PHP" ]]; then # setup / update PHP modules
$STD systemctl stop php${CURRENT_PHP}-fpm || true $STD apt-get install -y "$MODULE_LIST"
$STD systemctl disable php${CURRENT_PHP}-fpm || true
fi
$STD apt-get install -y $MODULE_LIST
msg_ok "Setup PHP $PHP_VERSION" msg_ok "Setup PHP $PHP_VERSION"
if [[ "$PHP_FPM" == "YES" ]]; then # optional stop old PHP-FPM service
$STD systemctl enable php${PHP_VERSION}-fpm if [[ "$PHP_FPM" == "YES" && -n "$CURRENT_PHP" && "$CURRENT_PHP" != "$PHP_VERSION" ]]; then
$STD systemctl restart php${PHP_VERSION}-fpm $STD systemctl stop php"${CURRENT_PHP}"-fpm || true
$STD systemctl disable php"${CURRENT_PHP}"-fpm || true
fi fi
# Patch all relevant php.ini files # Patch all relevant php.ini files
local PHP_INI_PATHS=("/etc/php/${PHP_VERSION}/cli/php.ini") local PHP_INI_PATHS=("/etc/php/${PHP_VERSION}/cli/php.ini")
[[ "$PHP_FPM" == "YES" ]] && PHP_INI_PATHS+=("/etc/php/${PHP_VERSION}/fpm/php.ini") [[ "$PHP_FPM" == "YES" ]] && PHP_INI_PATHS+=("/etc/php/${PHP_VERSION}/fpm/php.ini")
[[ "$PHP_APACHE" == "YES" ]] && PHP_INI_PATHS+=("/etc/php/${PHP_VERSION}/apache2/php.ini") [[ "$PHP_APACHE" == "YES" ]] && PHP_INI_PATHS+=("/etc/php/${PHP_VERSION}/apache2/php.ini")
for ini in "${PHP_INI_PATHS[@]}"; do for ini in "${PHP_INI_PATHS[@]}"; do
if [[ -f "$ini" ]]; then if [[ -f "$ini" ]]; then
$STD msg_info "Patching $ini" $STD msg_info "Patching $ini"
@ -477,6 +468,28 @@ function setup_php() {
$STD msg_ok "Patched $ini" $STD msg_ok "Patched $ini"
fi fi
done done
# patch Apache configuration if needed
if [[ "$PHP_APACHE" == "YES" ]]; then
for mod in $(ls /etc/apache2/mods-enabled/ 2>/dev/null | grep -E '^php[0-9]\.[0-9]\.conf$' | sed 's/\.conf//'); do
if [[ "$mod" != "php${PHP_VERSION}" ]]; then
$STD a2dismod "$mod" || true
fi
done
$STD a2enmod mpm_prefork
$STD a2enmod "php${PHP_VERSION}"
$STD systemctl restart apache2 || true
fi
# enable and restart PHP-FPM if requested
if [[ "$PHP_FPM" == "YES" ]]; then
if systemctl list-unit-files | grep -q "php${PHP_VERSION}-fpm.service"; then
$STD systemctl enable php"${PHP_VERSION}"-fpm
$STD systemctl restart php"${PHP_VERSION}"-fpm
else
msg_warn "FPM requested but service php${PHP_VERSION}-fpm not found"
fi
fi
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@ -794,7 +807,7 @@ function fetch_and_deploy_gh_release() {
local max_retries=3 retry_delay=2 attempt=1 success=false resp http_code local max_retries=3 retry_delay=2 attempt=1 success=false resp http_code
while ((attempt <= max_retries)); do while ((attempt <= max_retries)); do
resp=$(curl $api_timeout -fsSL -w "%{http_code}" -o /tmp/gh_rel.json "${header[@]}" "$api_url") && success=true && break resp=$(curl "$api_timeout" -fsSL -w "%{http_code}" -o /tmp/gh_rel.json "${header[@]}" "$api_url") && success=true && break
sleep "$retry_delay" sleep "$retry_delay"
((attempt++)) ((attempt++))
done done
@ -832,7 +845,7 @@ function fetch_and_deploy_gh_release() {
[[ -z "$url" ]] && url="https://github.com/$repo/archive/refs/tags/v$version.tar.gz" [[ -z "$url" ]] && url="https://github.com/$repo/archive/refs/tags/v$version.tar.gz"
filename="${app_lc}-${version}.tar.gz" filename="${app_lc}-${version}.tar.gz"
curl $download_timeout -fsSL -o "$tmpdir/$filename" "$url" || { curl "$download_timeout" -fsSL -o "$tmpdir/$filename" "$url" || {
msg_error "Download failed: $url" msg_error "Download failed: $url"
rm -rf "$tmpdir" rm -rf "$tmpdir"
return 1 return 1
@ -888,7 +901,7 @@ function fetch_and_deploy_gh_release() {
fi fi
filename="${url_match##*/}" filename="${url_match##*/}"
curl $download_timeout -fsSL -o "$tmpdir/$filename" "$url_match" || { curl "$download_timeout" -fsSL -o "$tmpdir/$filename" "$url_match" || {
msg_error "Download failed: $url_match" msg_error "Download failed: $url_match"
rm -rf "$tmpdir" rm -rf "$tmpdir"
return 1 return 1
@ -931,7 +944,7 @@ function fetch_and_deploy_gh_release() {
} }
filename="${asset_url##*/}" filename="${asset_url##*/}"
curl $download_timeout -fsSL -o "$tmpdir/$filename" "$asset_url" || { curl "$download_timeout" -fsSL -o "$tmpdir/$filename" "$asset_url" || {
msg_error "Download failed: $asset_url" msg_error "Download failed: $asset_url"
rm -rf "$tmpdir" rm -rf "$tmpdir"
return 1 return 1
@ -1007,7 +1020,7 @@ function fetch_and_deploy_gh_release() {
local target_file="$app" local target_file="$app"
[[ "$use_filename" == "true" ]] && target_file="$filename" [[ "$use_filename" == "true" ]] && target_file="$filename"
curl $download_timeout -fsSL -o "$target/$target_file" "$asset_url" || { curl "$download_timeout" -fsSL -o "$target/$target_file" "$asset_url" || {
msg_error "Download failed: $asset_url" msg_error "Download failed: $asset_url"
rm -rf "$tmpdir" rm -rf "$tmpdir"
return 1 return 1