Skip to content

upgrade-php-trixie-8.5.sh purges PHP 8.3 before installing 8.5 – a stale release value in ncp.cfg leaves the box without any PHP #2159

Open

Description

@Knubbel

Summary

The automatic NCP main update (v1.58.0 → v1.59.0, cron job /etc/cron.daily/ncp-autoupdate)
took my Nextcloud instance completely offline. Apache kept serving requests, but no PHP handler
was left
, so index.php was delivered as plain text and /login returned 404. Nextcloud's own
log stayed empty, because no PHP was running to write to it.

Three independent problems combined into a total outage:

  1. ncp-update-nc.d/upgrade-php-trixie-8.5.sh removes all php8.3-* packages first and only
    then tries to install php8.5. Any failure in between leaves the system with no PHP at all.
  2. The installer targets -t "$RELEASE", where RELEASE comes from ncp.cfg. That file still
    contained "release": "bookworm" although the system runs Debian 13 (trixie), so the
    install step could never succeed.
  3. php_restore() then writes a new /etc/apt/sources.list.d/php.list next to the existing
    php.sources. Both pin different Signed-By keyrings, so apt refuses to read the source list
    at all – every later apt call fails, including a manual reinstall of PHP 8.3.

On top of that, the rollback trap prints PHP upgrade has been successfully reverted although
nothing was restored. That message is actively misleading: it hides the outage during unattended
runs and sends the operator down the wrong path.

Environment

Hardware Raspberry Pi 4 Model B Rev 1.5 (arm64)
OS Armbian 26.8.3, Debian 13 trixie
NCP v1.58.0 → v1.59.0 (pulled automatically at 06:25)
PHP before 8.3.36 from packages.sury.org (debsuryorg-archive-keyring 2025.11.18)
PHP after none (php -v → command not found)
Nextcloud 33.0.10 → auto-update target 34.0.5
Web server Apache 2.4.68 (mpm_event) + mod_proxy_fcgi → /run/php/php8.3-fpm.sock

/usr/local/etc/ncp.cfg at the time of the failure:

{ "release": "bookworm", "php_version": "8.3", "nextcloud_version": "34.0.2" }

Steps to reproduce

  1. Install NCP on a trixie system where ncp.cfg still carries "release": "bookworm"
    (observed after an in-place bookworm → trixie upgrade).
  2. Let NCP v1.59.0 (or later) install itself via /etc/cron.daily/ncp-autoupdate, or run
    sudo ncp-update.
  3. ncp-update re-rolls /usr/local/bin/ncp-update-nc.d/ and starts nc-autoupdate-nc in the
    same run
    , so update-nc.sh picks the new branch
    elif ! is_more_recent_than "33.0.0" "$NCVER" && is_more_recent_than "8.5.0" "$PHPVER.0" && DEBIAN_VERSION -ge 13
    and calls upgrade-php-trixie-8.5.sh.
  4. Watch /var/log/ncp.log and /var/log/apt/history.log.

Expected behaviour

Either the upgrade to PHP 8.5 succeeds, or the system stays on a working PHP 8.3. A failed
upgrade must never leave the web server without a handler.

Actual behaviour

06:25  ncp-autoupdate:  Downloading updates … Performing updates
06:25  all files in ncp-update-nc.d/ get the run's timestamp, incl. upgrade-php-trixie-8.5.sh
06:25  Running nc-autoupdate-nc
06:46  apt: php8.3-* removed (--purge), php8.5 never installed
06:46  E: Conflicting values set for option Signed-By regarding source
       https://packages.sury.org/php/ trixie:
       debsuryorg-archive-keyring.gpg != deb.sury.org-php.gpg
06:46  E: The list of sources could not be read.
06:46  "PHP upgrade has been successfully reverted"     <-- nothing was reverted

Aftermath on the box:

  • systemctl status php8.3-fpm → Unit php8.3-fpm.service could not be found
  • /etc/apache2/conf-available/php8.3-fpm.conf gone, a2query -m proxy_fcgi → not enabled
  • curl -k -sS https://127.0.0.1/status.php → HTML source instead of JSON
  • /var/log/nextcloud/nextcloud.log unchanged since the night (nothing runs, nothing logs)
  • apt-cache policy php8.3-cli → E: Conflicting values set for option Signed-By …

Root cause analysis

A. Purge-before-install ordering.
upgrade-php-trixie-8.5.sh runs

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

as the very first action of the main routine. There is no snapshot, no dependency-guarded
replacement, and no check that the target packages are actually installable. A single failure
later in the script is fatal for the whole service.

B. release taken from ncp.cfg without validating it against the running distribution.
/usr/local/etc/library.sh around line 58:

RELEASE=$(jq -r .release < "$NCPCFG")

ncp.cfg is not migrated on a distribution upgrade, so bookworm survived into a trixie system.
The install step uses apt-get install -t "$RELEASE" … and fails.

C. Rollback writes a conflicting source file.
The php_restore() trap does roughly

echo "deb [signed-by=/usr/share/keyrings/debsuryorg-archive-keyring.gpg] https://packages.sury.org/php/ trixie main" \
  > /etc/apt/sources.list.d/php.list

Debian's deb822 php.sources (created earlier, keyring deb.sury.org-php.gpg) is left in place.
Two files, one URI, two different Signed-By values → apt aborts. This turns a recoverable
situation into a locked package manager, and it happens during the rollback path, i.e. exactly
when the system needs to install packages.

D. Success message without verification.
The trap reports success unconditionally. A rollback path should verify
php -v / systemctl is-active php8.3-fpm before printing "successfully reverted", otherwise the
message is worse than silence.

Impact

Complete unavailability of the Nextcloud instance until manually repaired (in my case ~6 hours,
because it happened during the night and the operator had to diagnose it first). Recovery required
manually restoring the sury source, disabling php.sources, resetting release to trixie,
reinstalling PHP 8.3 and re-enabling the FastCGI configuration.

Proposed fixes

  1. Validate RELEASE against the running distribution and refuse to continue on a mismatch:

    DEBIAN_VERSION=$(lsb_release -sc)
    if [ "$RELEASE" != "$DEBIAN_VERSION" ]; then
      echo "ncp.cfg release '$RELEASE' does not match running '$DEBIAN_VERSION' – aborting PHP upgrade" >&2
      exit 1
    fi
  2. Never purge before the new packages are installable. Use
    apt-get install -s -t "$RELEASE" php8.5-fpm … as a pre-flight, or install 8.5 alongside 8.3
    and only remove 8.3 after php8.5-fpm reports active.

  3. Make php_restore() idempotent and non-conflicting. Either rewrite the existing
    php.sources (deb822) instead of creating php.list, or move/disable php.sources first.
    A single source definition per URI is enough.

  4. Verify the rollback before announcing it:

    if php -v >/dev/null 2>&1 && systemctl is-active --quiet php8.3-fpm; then
      echo "PHP 8.3 restored"
    else
      echo "ROLLBACK FAILED – no working PHP, manual intervention required" >&2
    fi
  5. Do not re-roll ncp-update-nc.d/ and trigger nc-autoupdate-nc in the same run, or at
    least honour an explicit opt-out. Users who pin a PHP version currently have no way to stay
    pinned: the stub is restored on every NCP main update and the same run executes it.

Workaround for affected users

# 1. Unblock apt – keep only one sury source definition
sudo mv /etc/apt/sources.list.d/php.sources /etc/apt/sources.list.d/php.sources.disabled

# 2. Align ncp.cfg with the running distribution (backup first)
sudo cp /usr/local/etc/ncp.cfg /root/ncp.cfg.bak
sudo jq '.release = "trixie"' /usr/local/etc/ncp.cfg > /tmp/ncp.cfg && sudo mv /tmp/ncp.cfg /usr/local/etc/ncp.cfg

# 3. Reinstall PHP 8.3 and restore the Apache handler
sudo apt-get update && sudo apt-get install -y php8.3 php8.3-fpm php8.3-cli php8.3-{curl,gd,imagick,intl,mbstring,mysql,opcache,readline,xml,zip,bcmath,gmp}
sudo a2enmod proxy_fcgi && sudo a2enconf php8.3-fpm && sudo systemctl restart php8.3-fpm apache2

# 4. Prevent the upgrade path from running again
sudo chmod a-x /etc/cron.daily/ncp-autoupdate /etc/cron.daily/ncp-autoupdate-nc
sudo cp /usr/local/bin/ncp-update-nc.d/upgrade-php-trixie-8.5.sh{,.original}
printf '#!/bin/bash\n# UPGRADE DISABLED – see upstream issue\nexit 0\n' | sudo tee /usr/local/bin/ncp-update-nc.d/upgrade-php-trixie-8.5.sh >/dev/null

# 5. Verify
curl -k -sS https://127.0.0.1/status.php   # must return JSON with "installed":true

Additional note

The same run also raised nextcloud_version handling questions on my box, but I could not tell
whether 34.0.5 was expected at that point – the PHP purge is the part I am confident about, and
it is the one that caused the outage.

Happy to test a patched upgrade-php-trixie-8.5.sh on this machine (arm64, trixie, NCP v1.59.0).

Activity

  1. martinwilco commented on Nov 8, 2026

    @martinwilco

    I had the same problem. ncp.cfg said "bookworm" and PHP 8.4, but "trixie" and PHP 8.4 were installed.
    I manually changed it to "trixie" and then ran the update again. This time, it aborted due to an error with PHP 8.5 posix.
    Adding the following line to upgrade-php-trixie-8.5.sh after "apt-get install -y --no-install-recommends -t "$RELEASE" "${PHP_PACKAGES_NEW[@]}"" made the update finish successfully:
    chmod 755 "/etc/php/${PHPVER_NEW}" "/etc/php/${PHPVER_NEW}/mods-available"
    I now have a working NCP 1.59.0 instance with NC 34.0.5 and PHP 8.5.12.

  2. Habrokomes commented on Nov 8, 2026

    @Habrokomes

    Thank you. I'm on an RPI 5 with Armbian Trixie, the automatic update killed my NCP completely. The workaround worked with no problems at all. I needed to run clear-php-opcache to clear up the WebDav connection, and then everything was running again.

  3. schoetju commented on Nov 9, 2026

    @schoetju
    Contributor

    Hi all, i am using debian install (on some old thin client) - and the update crashed my instance too.

    I am sharing few lines out of /var/log/ncp.log that are showing, where it went wrong.

    [ nc-limits ] (Sa 7. Nov 18:14:01 CET 2026)
    Using 6068742144 for PHP max memory
    Using 6068742144 for PHP max memory
    Installing template 'php/90-ncp.ini.sh' to '/etc/php/8.5/fpm/conf.d/90-ncp.ini'...
    Installing template 'php/90-ncp.ini.sh' to '/etc/php/8.5/fpm/conf.d/90-ncp.ini'...
    Using 20 PHP threads
    Using 20 PHP threads
    Installing template 'php/pool.d.www.conf.sh' to '/etc/php/8.5/fpm/pool.d/www.conf'...
    Installing template 'php/pool.d.www.conf.sh' to '/etc/php/8.5/fpm/pool.d/www.conf'...
    Installing template 'mysql/91-ncp.cnf.sh' to '/etc/mysql/mariadb.conf.d/91-ncp.cnf'...
    Installing template 'mysql/91-ncp.cnf.sh' to '/etc/mysql/mariadb.conf.d/91-ncp.cnf'...
    
    Enabling conf php8.5-fpm.
    To activate the new configuration, you need to run:
      systemctl reload apache2
    Installing template 'systemd/php-fpm.service.d.ncp.conf.sh' to '/etc/systemd/system/php8.5-fpm.service.d/ncp.conf'...
    Starting apache and php-fpm...
    Warning: The unit file, source configuration file or drop-ins of php8.5-fpm.service changed on disk. Run 'systemctl daemon-reload' to reload units.
    
    Fatal error: Uncaught Error: Call to undefined function posix_getuid() in /var/www/nextcloud/occ:15
    Stack trace:
    #0 /var/www/nextcloud/occ(32): dropPrivileges()
    #1 {main}
      thrown in /var/www/nextcloud/occ on line 15
    Something went wrong while upgrading PHP. Rolling back to version 8.3...
    
    

    Steps that i've taken as of now

    1. Restore of backup
    2. Prevent, that autoupdate crashes the system again (following @Knubbel 's suggestion)
      sudo chmod a-x /etc/cron.daily/ncp-autoupdate /etc/cron.daily/ncp-autoupdate-nc
    3. Followed @martinwilco 's suggestion
      3.1 "Adding the following line to upgrade-php-trixie-8.5.sh after "apt-get install -y --no-install-recommends -t "$RELEASE" "${PHP_PACKAGES_NEW[@]}"" made the update finish successfully:
      chmod 755 "/etc/php/${PHPVER_NEW}" "/etc/php/${PHPVER_NEW}/mods-available"

      3.2 Started the script upgrade-php-trixie-8.5.sh standalone (to see, that at least the PHP update is working fine --> it does).

    Finally i did the nextcloud update (by starting nc-update-nextcloud).

    All in all: Reached Nextcloud 34.0.5 and PHP 8.5.12 !

    the workaround

  4. armanian commented on Nov 12, 2026

    @armanian

    same here

  5. Glujaz commented on Nov 13, 2026

    @Glujaz

    Just got impacted today...

  6. Glujaz commented on Nov 13, 2026

    @Glujaz

    I solved the issue this way :

    I modified /usr/local/etc/ncp.cfg and used Trixie instead.

    Reinstalled PHP8.3 (commands suggested above)

    sudo apt-get update && sudo apt-get install -y php8.3 php8.3-fpm php8.3-cli php8.3-{curl,gd,imagick,intl,mbstring,mysql,opcache,readline,xml,zip,bcmath,gmp}
    sudo a2enmod proxy_fcgi && sudo a2enconf php8.3-fpm && sudo systemctl restart php8.3-fpm apache2
    

    And simply ran :
    /usr/local/bin/ncp-update-nc.d/upgrade-php-trixie-8.5.sh.

    Nextcloud was in maintenance mode after that, but this is easy to disable

    Now it is running perfectly, and I could do some nextcloud and nextcloudpi updates flawlessly.

  7. armanian commented on Nov 14, 2026

    @armanian

    I hope there will be a fix for this soon.

  8. Glujaz commented on Nov 14, 2026

    @Glujaz

    I mean, I proposed a commit 2 months ago for another bug, and yesterday during the fix, a "updated" nextcloudpi (it juste reinstalled the current version), and replaced my fix with the original problem. #2145

    And I know that nextcloudpi is getting deprecated... But it is the easiest solution for bare metal installation without docker.

  9. ApricotFarm commented on Nov 16, 2026

    @ApricotFarm

    @Glujaz Wait -- NCP is getting deprecated? Is there some kind of official statement of this?

  10. ApricotFarm commented on Nov 16, 2026

    @ApricotFarm

    Same problems as OP. I'm with @armanian ; I really hope there will be a fix for this soon. I've been using NCP for years now, and the upgrades have always gone smoothly for me. I really appreciate the work that folks have put in here on developing a workaround, but it would be great if the official installer/upgrader could handle this smoothly.

  11. Glujaz commented on Nov 16, 2026

    @Glujaz

    @Glujaz Wait -- NCP is getting deprecated? Is there some kind of official statement of this?

    It is supposed to be replaced by Nextcloud atomic, but this project seems to be dead or not very active anymore...

  12. m-breitbach commented on Nov 18, 2026

    @m-breitbach
    Contributor

    Sadly I also need to consider migrating away after many years using NextcloudPi. Probably moving to https://github.com/nextcloud/all-in-one, but the migration will be the funny part (NC versions must match exactly for a full migration, plus database conversion from MariaDB to Postgres).

  13. Knubbel commented on Nov 18, 2026

    @Knubbel
    Author

    I am very grateful for the time the developers invest into this project, so kudos to @theCalcaholic and all others for a great project!

    Is there anything I or we can do to help you fix this issue?

  14. garternicht commented on Nov 22, 2026

    @garternicht

    I can confirm that simply adding:
    chmod 755 "/etc/php/${PHPVER_NEW}" "/etc/php/${PHPVER_NEW}/mods-available"
    to the last line of
    /usr/local/bin/ncp-update-nc.d/upgrade-php-trixie-8.5.sh
    leads to a smooth upgrade from nextcloud 33.0.10 to 33.0.11 and from php 8.3 to 8.5 in one single step. Upgrading to 34.0.6 afterwards was without issues as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions