I have latest NextCloudPi version, but dated PHP version

,

Nextcloud version: 25.0.1.1
Operating system and version: Debian GNU/Linux 11. 5.15.32-v8+ (aarch64)
Apache or nginx version: Apache/2.4.56 (Debian)
PHP version (eg, 7.4): PHP 7.4.33

The issue you are facing:
I’m running NextCloudPi v1.52.0.

When I go to update to Nextcloud 26, using the NCP admin I get this message:
[ nc-update-nextcloud ] (Thu May 11 21:25:57 BST 2023) We need to upgrade PHP. This process cannot be performed from the web UI. Please use 'ncp-config' from the terminal (via SSH or direct access) to update Nextcloud instead. Future updates can again be run from the web UI

When I navigate ncp-config, I don’t see any option to update PHP. I understand that Nextcloud 26 requires an updated version of PHP.

Futher, I see that a past update to NCP included a PHP upgrade to 8.1. My machine was running at this time, so I’m confused why I don’t have that PHP update.

Is this the first time you’ve seen this error?: Yes

Steps to replicate it:

  1. Attempt to update using nc-update-nextcloud
  2. See error message
  3. Confirm that I’m running NextCloudPi v1.52.0 with PHP 7.4.33

Thank you!!

Sorry i do not use NextCloudPi . But you must differ between PHP in the web and PHP in the command line. Maybe there is the problem.

Can you list all php packages?
dpkg -l |grep php

Unfortunately I do not know if NextcloudPi has any special features when updating packages. Normally you get PHP 8.1 only when switching from Debian 11 (Bullseye) to Debian 12 (Bookworm). But I don’t know if NextcloudPi might include third party sources to allow updating PHP packages already on Debian 11 (Bullseye).

When you run ncp-config, look for the option to upgrade Nextcloud not PHP.

The process of upgrading to the newer version of Nextcloud is what triggers the PHP upgrade to the appropriate version.

Think about it this way: the NCP version you’re running supports upgrading to v26 NC and, in turn, will upgrade to PHP 8.1 when required (i.e. when you upgrade to v26 NC).

Thank you! I tried this and got a negative response.

Running nc-update-nextcloud
Current   Nextcloud version 25.0.1.1
Available Nextcloud version 26.0.1
Download Nextcloud 26.0.1...
Back up current instance...
check free space...
Maintenance mode enabled
backup database...
backup files...
backup /var/www/nextcloud-bkp_20230512_1683928341.tar.gz generated
Maintenance mode disabled
Storing backup at '/var/www/nextcloud-bkp_20230512_1683928341-25.0.1.1.tar.gz'...
Install Nextcloud 26.0.1...
Fix permissions...
Upgrade...
This version of Nextcloud requires at least PHP 8.0<br/>You are currently running 7.4.33. Please update your PHP version.Abort
Clean up...
Rolling back to backup /var/www/nextcloud-bkp_20230512_1683928341-25.0.1.1.tar.gz...
check free space...
extracting backup file /var/www/nextcloud-bkp_20230512_1683928341-25.0.1.1.tar.gz...
1 Like

Thanks! Here is what I’m seeing

dpkg -l |grep php
ii  php-common                           2:76                             all          Common files for PHP packages
ii  php-igbinary                         3.2.1+2.0.8-2                    arm64        igbinary PHP serializer
ii  php-redis                            5.3.2+4.3.0-2+deb11u1            arm64        PHP extension for interfacing with Redis
ii  php7.4                               7.4.33-1+deb11u3                 all          server-side, HTML-embedded scripting language (metapackage)
ii  php7.4-bcmath                        7.4.33-1+deb11u3                 arm64        Bcmath module for PHP
ii  php7.4-bz2                           7.4.33-1+deb11u3                 arm64        bzip2 module for PHP
ii  php7.4-cli                           7.4.33-1+deb11u3                 arm64        command-line interpreter for the PHP scripting language
ii  php7.4-common                        7.4.33-1+deb11u3                 arm64        documentation, examples and common module for PHP
ii  php7.4-curl                          7.4.33-1+deb11u3                 arm64        CURL module for PHP
ii  php7.4-fpm                           7.4.33-1+deb11u3                 arm64        server-side, HTML-embedded scripting language (FPM-CGI binary)
ii  php7.4-gd                            7.4.33-1+deb11u3                 arm64        GD module for PHP
ii  php7.4-gmp                           7.4.33-1+deb11u3                 arm64        GMP module for PHP
ii  php7.4-intl                          7.4.33-1+deb11u3                 arm64        Internationalisation module for PHP
ii  php7.4-json                          7.4.33-1+deb11u3                 arm64        JSON module for PHP
ii  php7.4-ldap                          7.4.33-1+deb11u3                 arm64        LDAP module for PHP
ii  php7.4-mbstring                      7.4.33-1+deb11u3                 arm64        MBSTRING module for PHP
ii  php7.4-mysql                         7.4.33-1+deb11u3                 arm64        MySQL module for PHP
ii  php7.4-opcache                       7.4.33-1+deb11u3                 arm64        Zend OpCache module for PHP
ii  php7.4-readline                      7.4.33-1+deb11u3                 arm64        readline module for PHP
ii  php7.4-xml                           7.4.33-1+deb11u3                 arm64        DOM, SimpleXML, XML, and XSL module for PHP
ii  php7.4-zip                           7.4.33-1+deb11u3                 arm64        Zip module for PHP

The instructions from @jtr are correct. However, if that doesn’t work, try to update to version 25.0.6 first (using ncp-config) and see if that successfully installs PHP 8.1.

In the meantime I’ll test the updater with NC26 and see if it needs fixing

4 Likes

Yes, this did the trick. Thank you!

When I updated to 25.0.6 using ncp-config is also updated the PHP version. I was then able to updated to NC26.

2 Likes

Hi, unfortunately in my case the advise to update to 25.x (25.0.7 in my case) using ncp-config via SSH did not trigger the php 7.4 to 8 upgrade either. Therefore I wasn’t able to update to Nextcloud 26 because the update will abort with “This version of Nextcloud requires at least PHP 8.0
You are currently running 7.4.33. Please update your PHP version.Abort”. The problem with the current PHP upgrade sequence in ncp-update-nc is that it will execute AFTER a Nextcloud update. But if the Nextcloud update fails (e.g. when trying to update from 25 to version 26 as described above), the script will exit before the upgrade sequence is even executed.

I figured out the following workaround: Before running the update to Nextcloud 26 via ncp-config I modified the binary /usr/local/bin/ncp-update-nc. I inserted the “Upgrading PHP” sequence at the beginning of the script and also had to remove the && is_more_recent_than "8.1.0" "${PHPVER}.0" bit of it and did set the PHPVER_OLD variable to “7.4” statically.

This is how my working /usr/local/bin/ncp-update-nc binary looks like:

#!/bin/bash

# Upgrade to a different Nextcloud version
#
# Copyleft 2017 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com>
# GPL licensed (see end of file) * Use at your own risk!
#
# Usage:
#       ncp-update-nc <version>
#
# More at https://ownyourbits.com
#

# test cases
####################
# - with and without moving datadir
# - failure at each test point
# -> must pass basic NC in tests.py ( meaning it's not in a broken state )

set -eE${DBG}

VER="$1"
BIN="${0##*/}"

source /usr/local/etc/library.sh

# pre-checks
####################
[[ "$VER" == "" ]] && { echo "Usage ${BIN} <version>"; exit 1; }
[[ -f /.docker-image ]] && BASEDIR=/data || BASEDIR=/var/www
cd "$BASEDIR"
DATADIR="$( get_nc_config_value datadirectory )"
ncc status &>/dev/null          || { [[ "$DBG" == x ]] && ncc status; echo "Nextcloud is currently down"; exit 1; }
[[ -d "${BASEDIR}/nextcloud-old" ]] && { echo "Nextcloud backup directory found. Interrupted or already running installation?"; exit 1; }
[[ -d "${BASEDIR}/nextcloud"     ]] || { echo "Nextcloud directory not found"      ; exit 1; }
[[ -d "$DATADIR"             ]] || { echo "Nextcloud data directory not found" ; exit 1; }

# check version
####################

[[ ${EUID} -eq 0 ]] && SUDO="sudo -u www-data"
CURRENT="$( $SUDO php /var/www/nextcloud/occ status | grep "version:" | awk '{ print $3 }' )"

MAJOR_CUR=$( cut -d. -f1 <<<"${CURRENT}" )
MAJOR_NEW=$( cut -d. -f1 <<<"${VER}" )
if [[ $((MAJOR_NEW - MAJOR_CUR)) -gt 1 ]]; then
  echo "Upgrade cannot skip major versions. Please upgrade one major version at a time" >&2
  exit 1
fi

if [[ "$MAJOR_NEW" -ge 24 ]] && [[ "$(lsb_release -r)" =~ .*10 ]]
then
  echo -e "NCP doesn't support Nextcloud versions greater than 23 with Debian 10 (Buster). Please run ncp-dist-upgrade."
  exit 1
fi

grep -qP "\d+\.\d+\.\d+" <<<"$CURRENT" || { echo "Malformed version $CURRENT"; exit 1; }
grep -qP "\d+\.\d+\.\d+" <<<"$VER"     || { echo "Malformed version $VER"    ; exit 1; }

echo "Current   Nextcloud version $CURRENT"
echo "Available Nextcloud version $VER"
is_more_recent_than "${VER}" "${CURRENT}" || { echo "Nothing to update"; exit 1; } # we want `exit 1` so the autoupdate doesn't notify success in this case


if ! is_more_recent_than '25.0.0' "${VER}" && is_more_recent_than "8.1.0" "${PHPVER}.0" && is_docker
then
  echo 'You need to upgrade to a later docker image in order to upgrade to Nextcloud 25+'
  exit 1
fi

if ! is_docker && ! is_more_recent_than "24.0.0" "${NCVER}"
then
  (
  echo "Upgrading PHP..."
  export DEBIAN_FRONTEND=noninteractive
  PHPVER_OLD="7.4"
  PHPVER_NEW="8.1"
  PHP_PACKAGES_OLD=(php-{common,igbinary,redis,json} "php${PHPVER_OLD}" \
    "php${PHPVER_OLD}"-{curl,gd,fpm,cli,opcache,mbstring,xml,zip,fileinfo,ldap,intl,bz2,json,common,readline,mysql,bcmath,gmp})
  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
    rm /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

  # Setup apt repository for php 8
  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

  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
  )

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

fi

# make sure that cron.php is not running and there are no pending jobs
# https://github.com/nextcloud/server/issues/10949
pgrep -cf cron.php &>/dev/null && { pkill -f cron.php; sleep 3; }
pgrep -cf cron.php &>/dev/null && { echo "cron.php running. Abort"; exit 1; }
mysql nextcloud <<<"UPDATE oc_jobs SET reserved_at=0;"

# cleanup
####################
cleanup() {
  local RET=$?
  set +eE
  echo "Clean up..."
  rm -rf "$BASEDIR"/nextcloud.tar.bz2 "$BASEDIR"/nextcloud-old
  trap "" EXIT
  exit $RET
}
trap cleanup EXIT

# get new code
####################
URL="https://download.nextcloud.com/server/releases/nextcloud-$VER.tar.bz2"
echo "Download Nextcloud $VER..."
wget -q "$URL" -O nextcloud.tar.bz2 || { echo "Error downloading"; exit 1; }

# backup
####################
BKPDIR="$BASEDIR"
WITH_DATA=no
COMPRESSED=yes
LIMIT=0

echo "Back up current instance..."
set +eE
ncp-backup "$BKPDIR" "$WITH_DATA" "$COMPRESSED" "$LIMIT" # && false # test point
RET=$?
sync
set -eE

BKP_="$( ls -1t "$BKPDIR"/nextcloud-bkp_*.tar.gz 2>/dev/null | head -1 )"
[[ -f "$BKP_"  ]] || {                set +eE; echo "Error backing up"; false || cleanup; }
[[ $RET -ne 0  ]] && { rm -f "$BKP_"; set +eE; echo "Error backing up"; false || cleanup; }
BKP="$( dirname "$BKP_" )/$( basename "$BKP_" .tar.gz )-${CURRENT}.tar.gz"
echo "Storing backup at '$BKP'..."
mv "$BKP_" "$BKP"

# simple restore if anything fails from here
####################
rollback_simple() {
  set +eE
  trap "" INT TERM HUP ERR
  echo -e "Abort\nSimple roll back..."
  rm -rf "$BASEDIR"/nextcloud
  mv "$BASEDIR"/nextcloud-old "$BASEDIR"/nextcloud
  false || cleanup                 # so cleanup exits with 1
}
trap rollback_simple INT TERM HUP ERR

# replace code
####################
echo "Install Nextcloud $VER..."
mv -T nextcloud nextcloud-old
tar -xf nextcloud.tar.bz2             # && false # test point
rm -rf /var/www/nextcloud.tar.bz2

# copy old config
####################
cp nextcloud-old/config/config.php nextcloud/config/

# copy old themes
####################
cp -raT nextcloud-old/themes/ nextcloud/themes/

# copy old NCP apps
####################
for app in nextcloudpi previewgenerator; do
  if [[ -d nextcloud-old/apps/"${app}" ]]; then
    cp -r -L nextcloud-old/apps/"${app}" /var/www/nextcloud/apps/
  fi
done

#false # test point

# copy data if it was at the default location
####################
if [[ "$DATADIR" == "/var/www/nextcloud/data" ]] || [[ "$DATADIR" == "/data/nextcloud/data" ]]; then
  echo "Restore data..."
  mv -T nextcloud-old/data nextcloud/data
fi

# nc-restore if anything fails from here
####################
rollback() {
  set +eE
  trap "" INT TERM HUP ERR EXIT
  echo -e "Abort\nClean up..."
  rm -rf /var/www/nextcloud.tar.bz2 "$BASEDIR"/nextcloud-old
  echo "Rolling back to backup $BKP..."
  local TMPDATA
  mkdir -p "$BASEDIR/recovery/"
  TMPDATA="$( mktemp -d "$BASEDIR/recovery/ncp-data.XXXXXX" )" || { echo "Failed to create temp dir" >&2; exit 1; }
  [[ "$DATADIR" == "$BASEDIR/nextcloud/data" ]] && mv -T "$DATADIR" "$TMPDATA"
  ncp-restore "$BKP" || { echo "Rollback failed! Data left at $TMPDATA"; exit 1; }
  [[ "$DATADIR" == "$BASEDIR/nextcloud/data" ]] && { rm -rf "$DATADIR"; mv -T "$TMPDATA" "$DATADIR"; }
  rm "$BKP"
  echo "Rollback successful. Nothing was updated"
  exit 1
}
trap rollback INT TERM HUP ERR

# fix permissions
####################
echo "Fix permissions..."
chown -R www-data:www-data nextcloud
find nextcloud/ -type d -exec chmod 750 {} \;
find nextcloud/ -type f -exec chmod 640 {} \;

# upgrade
####################
echo "Upgrade..."
ncc='sudo -u www-data php nextcloud/occ'
$ncc upgrade      # && false # test point
$ncc | grep -q db:add-missing-indices && $ncc db:add-missing-indices -n
$ncc | grep -q db:add-missing-columns && $ncc db:add-missing-columns -n
$ncc | grep -q db:add-missing-primary-keys && $ncc db:add-missing-primary-keys -n
$ncc | grep -q db:convert-filecache-bigint && $ncc db:convert-filecache-bigint -n

# use the correct version for custom apps
NCVER="$(ncc status | grep "version:" | awk '{ print $3 }')"
if is_more_recent_than "21.0.0" "${NCVER}"; then
  NCPREV=/var/www/ncp-previewgenerator/ncp-previewgenerator-nc20
else
  # Install notify_push if not installed
  if ! is_app_enabled notify_push; then
    ncc app:install notify_push
    ncc app:enable  notify_push
    install_template nextcloud.conf.sh /etc/apache2/sites-available/nextcloud.conf
    a2enmod proxy proxy_http proxy_wstunnel
    apachectl -k graceful
    ## make sure the notify_push daemon is runnnig

    install_template systemd/notify_push.service.sh /etc/systemd/system/notify_push.service
    start_notify_push
    nc_domain="$(ncc config:system:get overwrite.cli.url)"
    set-nc-domain "${nc_domain}" || {
      echo "notify_push setup failed. You are probably behind a proxy"
      echo "Run 'ncc config:system:set trusted_proxies 15 --value=<proxy_IP>' and then 'ncc notify_push:setup https://<domain>/push to enable"
      echo "Check https://help.nextcloud.com/tags/ncp for support"
    }

  fi
  NCPREV=/var/www/ncp-previewgenerator/ncp-previewgenerator-nc21
fi
rm -rf /var/www/nextcloud/apps/previewgenerator
ln -snf "${NCPREV}" /var/www/nextcloud/apps/previewgenerator

# refresh completions
ncc _completion -g --shell-type bash -p ncc | sed 's|/var/www/nextcloud/occ|ncc|g' > /usr/share/bash-completion/completions/ncp

is_docker && {
  killall notify_push
  sleep 1
  start_notify_push
}

echo "Update completed successfully."
# done
####################
mkdir -p  "$DATADIR"/ncp-update-backups
mv "$BKP" "$DATADIR"/ncp-update-backups
chown -R www-data:www-data "$DATADIR"/ncp-update-backups
BKP="$DATADIR"/ncp-update-backups/"$( basename "$BKP" )"
echo "Backup stored at $BKP"

bash -c "sleep 5; source /usr/local/etc/library.sh; clear_opcache;" &>/dev/null &

For some reason I also had to setup the apt repository for php 8 BEFORE starting the whole upgrade process with:

sudo su
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ bullseye-security main" > /etc/apt/sources.list.d/php.list
apt-get update

After the sucessful upgrade to PHP 8.1 and Nextcloud 26.0.1 I reverted the content of the /usr/local/bin/ncp-update-nc back to its original state. Hope this helps anyone who has still issues with upgrading NextcloudPi with Debian 11 (bullseye) from PHP 7.4 to 8.1.

1 Like

Hi.

At last I don’t feel alone in this loop hole (NC25/php7 NC26/php8).
I only update via ncp web interface.
Never got the message telling me to update via ncp-config to update php…
I’ll try the console one.

As the automatic PHP8 install (mentioned by @theCalcaholic ) doesn’t work for me (I’m up to date with NC 25.0.8.2 from within NC) I tried the ncp-update-nc modified script by @abcd .
Doesn’t work either.
I’ve got this messages :

Running nc-update-nextcloud
/usr/local/bin/ncp-update-nc: line 2: $'\r': command not found
/usr/local/bin/ncp-update-nc: line 13: $'\r': command not found
/usr/local/bin/ncp-update-nc: line 19: $'\r': command not found
: invalid optioncp-update-nc: line 20: set: -
set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
/usr/local/bin/ncp-update-nc: line 21: $'\r': command not found
/usr/local/bin/ncp-update-nc: line 24: $'\r': command not found
: No such file or directoryc: line 25: /usr/local/etc/library.sh
/usr/local/bin/ncp-update-nc: line 26: $'\r': command not found
/usr/local/bin/ncp-update-nc: line 51: syntax error in conditional expression
'usr/local/bin/ncp-update-nc: line 51: syntax error near `]]
'usr/local/bin/ncp-update-nc: line 51: `if [[ "$MAJOR_NEW" -ge 24 ]] && [[ "$(lsb_release -r)" =~ .*10 ]]
Done. Press any key...

Any progress wit this?
I’m in the same loop whole.