Skip to content

Commit

Permalink
update-nc.sh: Implement upgrade of PHP to 8.3
Browse files Browse the repository at this point in the history
Signed-off-by: Tobias Knöppler <[email protected]>
  • Loading branch information
theCalcaholic committed Aug 18, 2024
1 parent 6da8994 commit c8968f3
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 8 deletions.
16 changes: 8 additions & 8 deletions bin/ncp-update-nc.d/update-nc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,14 @@ then
source /usr/local/etc/library.sh
export PHPVER
export RELEASE
#elif ! is_more_recent_than "29.0.0" "${NCVER}" && is_more_recent_than "8.3.0" "${PHPVER}.0" && [[ "$DEBIAN_VERSION" -ge 12 ]]
#then
# /usr/local/bin/ncp-update-nc.d/upgrade-php-bookworm-8.3.sh
#
# # Reload library.sh to reset PHPVER
# source /usr/local/etc/library.sh
# export PHPVER
# export RELEASE
elif ! is_more_recent_than "29.0.0" "${NCVER}" && is_more_recent_than "8.3.0" "${PHPVER}.0" && [[ "$DEBIAN_VERSION" -ge 12 ]]
then
/usr/local/bin/ncp-update-nc.d/upgrade-php-bookworm-8.3.sh

# Reload library.sh to reset PHPVER
source /usr/local/etc/library.sh
export PHPVER
export RELEASE
fi

# refresh completions
Expand Down
62 changes: 62 additions & 0 deletions bin/ncp-update-nc.d/upgrade-php-bookworm-8.3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env bash

echo "Upgrading PHP..."
export DEBIAN_FRONTEND=noninteractive
PHPVER_OLD="$PHPVER"
PHPVER_NEW="8.3"
PHP_PACKAGES_OLD=("php${PHPVER_OLD}" \
"php${PHPVER_OLD}"-{curl,gd,fpm,cli,opcache,mbstring,xml,zip,fileinfo,ldap,intl,bz2,mysql,bcmath,gmp,redis,common})
PHP_PACKAGES_NEW=("php${PHPVER_NEW}" \
"php${PHPVER_NEW}"-{curl,gd,fpm,cli,opcache,mbstring,xml,zip,fileinfo,ldap,intl,bz2,mysql,bcmath,gmp,redis,common})

php_restore() {
trap "" INT TERM HUP ERR
echo "Something went wrong while upgrading PHP. Rolling back to version ${PHPVER_OLD}..."
set +e
service "php${PHPVER_NEW}-fpm" stop
a2disconf php${PHPVER_NEW}-fpm
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ ${RELEASE%-security} main" > /etc/apt/sources.list.d/php.list
apt-get update
apt-get remove --purge -y "${PHP_PACKAGES_NEW[@]}"
apt-get install -y --no-install-recommends -t "$RELEASE" "${PHP_PACKAGES_OLD[@]}"
set_ncpcfg "php_version" "${PHPVER_OLD}"
install_template "php/opcache.ini.sh" "/etc/php/${PHPVER_NEW}/mods-available/opcache.ini"
run_app nc-limits
a2enconf "php${PHPVER_OLD}-fpm"
service "php${PHPVER_OLD}-fpm" start
service apache2 restart
echo "PHP upgrade has been successfully reverted"
set -e
}

trap php_restore INT TERM HUP ERR

apt-get update

clear_opcache

echo "Stopping apache and php-fpm..."
service "php${PHPVER_OLD}-fpm" stop
service apache2 stop

echo "Remove old PHP (${PHPVER_OLD})..."
a2disconf "php${PHPVER_OLD}-fpm"

apt-get remove --purge -y "${PHP_PACKAGES_OLD[@]}"

echo "Install PHP ${PHPVER_NEW}..."
install_with_shadow_workaround --no-install-recommends systemd
apt-get install -y --no-install-recommends -t "$RELEASE" "${PHP_PACKAGES_NEW[@]}"

set_ncpcfg "php_version" "${PHPVER_NEW}"
install_template "php/opcache.ini.sh" "/etc/php/${PHPVER_NEW}/mods-available/opcache.ini"
( set -e; export PHPVER="${PHPVER_NEW}"; run_app nc-limits )

a2enconf "php${PHPVER_NEW}-fpm"

echo "Starting apache and php-fpm..."
service "php${PHPVER_NEW}-fpm" start
service apache2 start
ncc status
rm -f /etc/apt/sources.list.d/php.list /etc/apt/trusted.gpg.d/php.gpg

0 comments on commit c8968f3

Please sign in to comment.