The Test and Live Nextcloud hosts were built on Ubuntu 20.04 LTS using PHP 7.4 which is now out of support. While this is not much of an issue Test, two of the apps for the Live system are exposed to the internet via a proxy so this is not good. Nextcloud 26 also drops support for PHP 7.4 as well, so an upgrade is essential.
Contents
Plan
The first thing we need to do is look at the dependencies of each version.
| Version | Linux | Apache | MariaDB | PHP |
| Nextcloud 24 | Ubuntu 20.04 LTS | Apache 2.4 | 10.5.19 | PHP 7.4.3 |
| Nextcloud 25 |
Ubuntu 20.04 LTS, Ubuntu 22.04 LTS |
Apache 2.4 | MariaDB 10.5, MariaDB 10.6 | PHP 7.4*, PHP 8.0, PHP 8.1 |
| Nextcloud 26 | Ubuntu 20.04 LTS, Ubuntu 22.04 LTS | Apache 2.4 | MariaDB 10.5, MariaDB 10.6 | PHP 8.0, PHP 8.1, PHP 8.2 |
While PHP 7.4 is now end of life it' still supported for Nextcloud 25 so we will update this at the same time. There's no need to upgrade any of the other components although if the other Nextcloud instance goes ahead I'll update MariaDB to 10.6 for consistency. The underlined versions are the recommended ones where there's a choice.
So from this we get a sequence of steps
- Apply latest OS patches ✅
- Apply Nextcloud 24.0.12 patch ✅
- Upgrade Nextcloud to version 25 ✅
- Upgrade PHP to version 8.1
- Test
- Consider upgrade Maria DB to 10.6
- Consider upgrade Nextcloud to version 26
- Test
As always before starting changes that might get interesting, the first step is to take a backup. Since this is running on my Geeklab, I can use a VM snapshot. While this needs a short outage, it means restores are also very fast as well. And when it's working I can release the snapshot.
| Components | Start Version | End Version |
| Linux | Ubuntu 20.04 LTS | Ubuntu 20.04 LTS |
| Apache 2 | Apache 2.4.41 | Apache 2.4.41 |
| MariaDB | 10.5.19 | 10.5.19 |
| PHP | 7.4.3 |
8.1.18 |
| Nextcloud | 25.0.6 | 25.0.6 |
The first task was to apply the latest Ubuntu patches using apt upgrade and a quick check there's no issues with disk space and that Joomla is also running nicely too. We do not want to do an upgrade once the PPA is added untill we've finished this.
Prepare
As I found with Test Nextcloud 26 Installation for another Nextcloud project, Ubuntu 20.04 does not have PHP 8.1 in any of the standard repositories. Ondej Sury packages PHP for Debian and kindly maintains a PPA for Ubuntu too which makes it so much simpler to install.
sudo apt-add-repository ppa:ondrej/php
sudo apt update
Done. So much easier than messing with .list files.
Install PHP 8.1 Packages for Nextcloud
The PPA will try to install PHP 8.2 given a chance and I do not want to do this yet since it's not supported by Nextcloud 25, so I'm going to install the php8.1- specific versions rather then just update to the latest automatically. Before allowing each update to proceed check the package it's going to install, plus any dependencies. I had some issues with this, so this is the cleanup up version that acutally worked.
A quick way to check what's currently there is to ask apt. And hopefully this still matches the list in the documentation you prepared while installing it it. I thought so.
apt list --installed | grep php
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
libapache2-mod-php7.4/focal-updates,focal-security,now 7.4.3-4ubuntu2.18 amd64 [installed,automatic]
php-apcu-bc/focal,now 10.05-2build1 amd64 [installed,automatic]
php-apcu/focal,now 5.1.18+4.0.11-1build1 amd64 [installed]
php-common/focal,now 2:74 all [installed,automatic]
php-fpm/focal,now 2:7.4+75 all [installed]
php-imagick/focal,now 3.4.4-4 amd64 [installed]
php-ldap/focal,now 2:7.4+75 all [installed]
php7.4-cgi/focal-updates,focal-security,now 7.4.3-4ubuntu2.17 amd64 [installed]
php7.4-cli/focal-updates,focal-security,now 7.4.3-4ubuntu2.18 amd64 [installed]
php7.4-common/focal-updates,focal-security,now 7.4.3-4ubuntu2.18 amd64 [installed,automatic]
php7.4-curl/focal-updates,focal-security,now 7.4.3-4ubuntu2.18 amd64 [installed]
php7.4-fpm/focal-updates,focal-security,now 7.4.3-4ubuntu2.17 amd64 [installed]
php7.4-gd/focal-updates,focal-security,now 7.4.3-4ubuntu2.18 amd64 [installed]
php7.4-intl/focal-updates,focal-security,now 7.4.3-4ubuntu2.18 amd64 [installed]
php7.4-json/focal-updates,focal-security,now 7.4.3-4ubuntu2.18 amd64 [installed]
php7.4-ldap/focal-updates,focal-security,now 7.4.3-4ubuntu2.17 amd64 [installed,automatic]
php7.4-mbstring/focal-updates,focal-security,now 7.4.3-4ubuntu2.18 amd64 [installed]
php7.4-mysql/focal-updates,focal-security,now 7.4.3-4ubuntu2.18 amd64 [installed]
php7.4-opcache/focal-updates,focal-security,now 7.4.3-4ubuntu2.18 amd64 [installed,automatic]
php7.4-readline/focal-updates,focal-security,now 7.4.3-4ubuntu2.18 amd64 [installed,automatic]
php7.4-xml/focal-updates,focal-security,now 7.4.3-4ubuntu2.18 amd64 [installed]
php7.4-zip/focal-updates,focal-security,now 7.4.3-4ubuntu2.18 amd64 [installed]
php7.4/focal-updates,focal-security,now 7.4.3-4ubuntu2.18 all [installed,automatic]
php/focal,now 2:7.4+75 all [installed]
Install PHP 8.1 Packages
Now we can start installing the PHP 8.1 components
sudo apt install php8.1-fpm
This will also bring in php8.1-cli, php8.1-common, php8.1-opcache and php8.1-readline
Then install the other required modules, and others installed for Nextcloud apps too.
sudo apt install php8.1-bz2 php8.1-curl php8.1-gd php8.1-intl php8.1-mbstring php8.1-mysql php8.1-xml php8.1-zip
sudo apt install php8.1-ldap
The php8.1apcu and php8.1-imagick packages request to bring in some php8.2 packages which I don't want, so these wait untill switchover.
Switchover
We now need to reapply the customisations we made to the original php.ini file. The old one will still be at /etc/php/7.4/apache2/php.ini or /etc/php/7.4/fpm and the new one will be at /etc/php/8.1/fpm/php.ini. You can compare both files, but if you've been keeping records of any changes it there should just be the two usual ones it warns about under installation messages.
post_max_size = 16M
upload_max_filesize = 16M
memory_limit = 512M
And now we can disable PHP 7.4. These had been installed using apache2 module instead of fpm hence the use of a2dismod. If you're using fpm then use the a2disconf command instead - you shouldn't need to use both.
sudo a2dismod php7.4
sudo a2disconf php7.4-fpm
We need to remove the php-apcu and php-imagick package now and install the php8.1 versions - if we need to roll back we'll have to revert these two packages.
sudo apt remove php-apcu php-imagicksudo apt install php8.1-apcu php8.1-imagick
And then enable PHP 8.1
sudo a2enmod proxy_fcgi
sudo a2enconf php8.1-fpm
sudo systemctl start php8.1-fpm
sudo systemctl restart apache2
And now login in as an administrator and check under Settings > Administration : System that it's now showing PHP 8.1.18.
The first time I did this I forgot about the php-ldap component, which meant nobody could log in, not even the non-ldap users. Doing the apt list --intalled | grep php is a good cross check that you've not missed anything. And of course I've added this to the system doc for future reference.
Remove old version
As we no longer need the old Ubuntu-supplied PHP packages they should be removed, not just to reduce clutter but as one of the reasons for the upgrade is the ending of security patches it would be very difficult for somebody to exploit a 7.4 bug if it's no longer installed. Check the list of packages to be removed each time before allowing the command to continue, just to be sure it's not about to do something silly.
sudo apt remove php
sudo apt remove php7.4 php-mysql php-ldap
sudo apt remove php7.4-cgi php7.4-curl php7.4-gd php-intl php7.4-mbstring php7.4-xml php-7.4zip php7.4-common
sudo apt remove php7.4-common
sudo apt autoremove
A final check of what's still installed should show just php8.1 packages
sudo apt list --installed | grep php
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
php-common/focal,now 2:75 all [installed,upgradable to: 2:93+ubuntu20.04.1+deb.sury.org+2]
php8.1-apcu/focal,now 5.1.22+4.0.11-2+ubuntu20.04.1+deb.sury.org+1 amd64 [installed]
php8.1-bz2/focal,now 8.1.18-1+ubuntu20.04.1+deb.sury.org+1 amd64 [installed]
php8.1-cli/focal,now 8.1.18-1+ubuntu20.04.1+deb.sury.org+1 amd64 [installed,automatic]
php8.1-common/focal,now 8.1.18-1+ubuntu20.04.1+deb.sury.org+1 amd64 [installed,automatic]
php8.1-curl/focal,now 8.1.18-1+ubuntu20.04.1+deb.sury.org+1 amd64 [installed]
php8.1-fpm/focal,now 8.1.18-1+ubuntu20.04.1+deb.sury.org+1 amd64 [installed]
php8.1-gd/focal,now 8.1.18-1+ubuntu20.04.1+deb.sury.org+1 amd64 [installed]
php8.1-imagick/focal,now 3.7.0-3+ubuntu20.04.1+deb.sury.org+1 amd64 [installed]
php8.1-intl/focal,now 8.1.18-1+ubuntu20.04.1+deb.sury.org+1 amd64 [installed]
php8.1-ldap/focal,now 8.1.18-1+ubuntu20.04.1+deb.sury.org+1 amd64 [installed]
php8.1-mbstring/focal,now 8.1.18-1+ubuntu20.04.1+deb.sury.org+1 amd64 [installed]
php8.1-mysql/focal,now 8.1.18-1+ubuntu20.04.1+deb.sury.org+1 amd64 [installed]
php8.1-opcache/focal,now 8.1.18-1+ubuntu20.04.1+deb.sury.org+1 amd64 [installed,automatic]
php8.1-readline/focal,now 8.1.18-1+ubuntu20.04.1+deb.sury.org+1 amd64 [installed,automatic]
php8.1-xml/focal,now 8.1.18-1+ubuntu20.04.1+deb.sury.org+1 amd64 [installed]
php8.1-zip/focal,now 8.1.18-1+ubuntu20.04.1+deb.sury.org+1 amd64 [installed]
And we can update php-common to Sury's version with a final upgrade.
sudo apt upgrade
And we're done. The PHP 7.4 configuration files are still in /etc/php/7.4 and may be worth holding onto for a few weeks just in case of any issues, but add a note to your diary to purge them.
Aftermath
After a little bit of testing this can be repeated on the Live system.
I didn't notice any PHP related issues. About an hour after it was installed I noticed that Settings > Administration : Overview : Update announced that Nextcloud 26.0.1 was now available as an update and that all apps were compatible, so we're now good to go on that.
And of course I need to release the snapshot I took at the start once the normal backup has completed.