Compare commits

...

2 Commits

Author SHA1 Message Date
13af56a077 better verbose output 2025-07-22 11:47:41 +02:00
513f618f38 tools.func: increase setup_php function 2025-07-22 11:43:59 +02:00

View File

@ -396,9 +396,10 @@ function setup_php() {
COMBINED_MODULES="${DEFAULT_MODULES}"
fi
# Deduplicate modules
# Deduplicate
COMBINED_MODULES=$(echo "$COMBINED_MODULES" | tr ',' '\n' | awk '!seen[$0]++' | paste -sd, -)
# Get current PHP-CLI version
local CURRENT_PHP=""
if command -v php >/dev/null 2>&1; then
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
fi
# Build module list
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"
for mod in "${MODULES[@]}"; do
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
if [[ "$PHP_FPM" == "YES" ]]; then
MODULE_LIST+=" php${PHP_VERSION}-fpm"
fi
# install apache2 with PHP support if requested
if [[ "$PHP_APACHE" == "YES" ]]; then
$STD apt-get install -y apache2 libapache2-mod-php${PHP_VERSION}
$STD systemctl restart apache2 || true
if ! dpkg -l | grep -q "libapache2-mod-php${PHP_VERSION}"; then
$STD msg_info "Installing Apache with PHP${PHP_VERSION} support"
$STD apt-get install -y apache2 libapache2-mod-php"${PHP_VERSION}"
$STD msg_ok "Setup Apache with PHP${PHP_VERSION}"
fi
fi
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
$STD a2enmod php${PHP_VERSION}
$STD systemctl restart apache2 || true
fi
if [[ "$PHP_FPM" == "YES" ]] && [[ -n "$CURRENT_PHP" ]]; then
$STD systemctl stop php${CURRENT_PHP}-fpm || true
$STD systemctl disable php${CURRENT_PHP}-fpm || true
fi
$STD apt-get install -y $MODULE_LIST
# setup / update PHP modules
$STD apt-get install -y "$MODULE_LIST"
msg_ok "Setup PHP $PHP_VERSION"
if [[ "$PHP_FPM" == "YES" ]]; then
$STD systemctl enable php${PHP_VERSION}-fpm
$STD systemctl restart php${PHP_VERSION}-fpm
# optional stop old PHP-FPM service
if [[ "$PHP_FPM" == "YES" && -n "$CURRENT_PHP" && "$CURRENT_PHP" != "$PHP_VERSION" ]]; then
$STD systemctl stop php"${CURRENT_PHP}"-fpm || true
$STD systemctl disable php"${CURRENT_PHP}"-fpm || true
fi
# Patch all relevant php.ini files
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_APACHE" == "YES" ]] && PHP_INI_PATHS+=("/etc/php/${PHP_VERSION}/apache2/php.ini")
for ini in "${PHP_INI_PATHS[@]}"; do
if [[ -f "$ini" ]]; then
$STD msg_info "Patching $ini"
@ -477,6 +468,28 @@ function setup_php() {
$STD msg_ok "Patched $ini"
fi
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
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"
((attempt++))
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"
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"
rm -rf "$tmpdir"
return 1
@ -888,7 +901,7 @@ function fetch_and_deploy_gh_release() {
fi
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"
rm -rf "$tmpdir"
return 1
@ -931,7 +944,7 @@ function fetch_and_deploy_gh_release() {
}
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"
rm -rf "$tmpdir"
return 1
@ -1007,7 +1020,7 @@ function fetch_and_deploy_gh_release() {
local target_file="$app"
[[ "$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"
rm -rf "$tmpdir"
return 1