Force NC 26.0.4 to use PHP 8.1

I have both various Ubuntu 20 and 22 and some have PHP 8.0 as the default Nextcloud PHP version used. Even if I switch to 8.1 and verify via php -v, NC still uses old version. Done a2enmod and a2dismod various time, and narrowed the issue down to missing module for Apache to use.

Question is, how do I create this module and then have NC use the new module PROPERLY?

Thank you.

PHP 8.0 used by Nextcloud

PHP 8.1 used by Nextcloud

Nextcloud still uses PHP 8.0 even after I switched to 8.1 via a2enmod php8.1 since no 8.1 exists for Apache.

php -v only shows which binary is linked to your cli-command /usr/bin/php. It usually doesn’t show what version a specific vhost of apache is using.

You see where php8.0 is used, there is the php8.0.load in the /etc/apache2/mods-enabled folder (and no other php version). So it is clear that it uses php 8.0.
If you want to enable a specific module, it must be present, so check the /etc/apache2/mods-available folder if a never php version is available. I’d disable the old one before enabling the new one. If the new version is within the mods-available you probably missed to install a package (some libapache-mod-php*). You can search for them
apt-cache search libapache2-mod-php

On the long run, if you only use your server for Nextcloud and don’t need several php versions in parallel, I’d just keep the one I want to use in order to avoid any confusion.

1 Like

Run:

for package in $(echo `dpkg -l | awk '/^ii.*php8.0/ {print $2}' | sed 's/php8.0/php8.1/g'`); do sudo apt-get -y install $package; done

and update-alternatives not only for “php” bu do it for all:

for linkgroup in `ls /var/lib/dpkg/alternatives/ | grep -E "ph(ar|p)"`; do sudo update-alternatives --config $linkgroup; done

Hope this helps
much luck!