Oct 18, 2023 | Cloud, Tutorials

Upgrading Ubuntu: From 20.04 to 22.04 with Nextcloud 26 and PHP 8.1

by

Every couple of years Ubuntu brings out a new LTS version of its operating system and with it comes a bundle of new applications and dependencies. This can be both exciting and challenging for sys-admins who need to make everything work after an upgrade. One of the updated features in Ubuntu 22.04 is the transition from PHP7.x to PHP8.x. This brings a boost in performance, sparkling new features and longer support. To ease the pain of making the jump, we will go through the steps needed to upgrade your Ubuntu server to 22.04 and your Nextcloud to version 26 with PHP8.x. Hold on to your Bermudas and let´s jump in.

Preparation

Before we make any irreversible changes let’s prepare our system so we have a good base to come back should anything go wrong (it won’t but you never know). We will start by making sure our current server is up to date and all the packages are installed.

sudo apt update
sudo apt upgrade
sudo apt autoremove

Here would be a very good point to make a backup or snapshot of your server as we have an up-to-date working system. If anything were to happen or you make a mistake, you can always come back to this point and start again. Additionally, you should consider allowing port 1022 for later, as you are probably doing this process over SSH, more on this later. Just as a side note, we take no responsibility for lost data, so we urge you to make a backup to recover from if things go south.

Moving on to the next step we want to take note of the PHP modules we currently have installed on the server. We will need these to install the corresponding versions later. Quick tip: You don’t need to worry about php-json as it will already be included in PHP8. First of all we will list the current modules we have on our current PHP version, you can do this with the following two commands:

php -m

dpkg --get-selections | grep php

php -m
[PHP Modules]
apc
apcu
bcmath
calendar
Core
ctype
curl
date
dom
exif
…

These are all of the modules currently on the system and it´s a good idea to save this list in order to install the correct ones later. If you have already manually installed all of the modules before with the older version you can copy this command and just replace the version number. Copy it into your favourite editor and use the find and replace function to find “7.4” and replace it with “8.1”. This can be done again with future versions and saves you time typing it out every time. Now we know what modules we want to install for later let’s move onto the upgrading part.

Dist-Upgrade

Now the fun part, we will prepare to upgrade our distribution to the next version, but first we need to confirm a few things. We need to make sure that we find out what distribution version we currently are on so that we don’t skip a version. If for some reason you are still on Ubuntu 18.04 you would need to upgrade to 20.04 first before going to 22.04.
First let’s check our distribution:

lsb_release -a
 
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.6 LTS
Release: 20.04
Codename: focal

Great, this is our current version and we can go straight to the next step of starting the upgrade. Be aware you may need a coffee in between as a Dist-Upgrade can take some time to process depending on your system. To start the process we enter this command which starts wizard:

    
sudo do-release-upgrade

This will ask you a series of questions regarding the process and we will go through them now.

As we will likely be doing this over SSH, the wizard will ask you if you would like to run a daemon on port 1022 in case anything crashes during the process. Always accept this one as this will allow you to recover the instance over this port and continue the process. If you haven’t already done so make sure this port is free on your machine or firewall. Afterwards just hit enter to continue.

In the upcoming stages, you will be asked to confirm the installation of all the new packages for the new distribution. Naturally, we want to proceed with this, so simply agree on the next two screens as well. The first of which will ask if restarts are allowed, if you are doing a Dist-Upgrade your server won’t be reachable anyway. So whether you restart or not is irrelevant just hit enter to continue the process.

The following question will ask if you want to remove obsolete packages which are left over from the upgrade. You can go ahead and just get rid of these as they just take up space.

Finally, you will be asked to restart your system, and it’s always a good idea to do so right after because it will only take a minute. Now, your server has the latest version of Ubuntu and is ready to be configured for PHP.

Configuring PHP

We are now ready to set up our PHP to use version 8.1. The reason we use 8.1 first is that Nextcloud Version 25 is not compatible with versions higher than this. If you go straight to 8.2, your Nextcloud will not function as intended. If you intend to upgrade to 8.2, you will need to do it after upgrading your Nextcloud to version 26.

Since we have already performed the Dist-upgrade, it might have already installed a few modules prepared for PHP 8.1. However, we need to ensure that we install all the additional modules required for Nextcloud. If we compare our list from earlier, we need to install all the remaining modules. In general, you will need the following:

sudo apt install php8.1-gd php8.1-mysql php8.1-curl php8.1-mbstring php8.1-intl php8.1-gmp php8.1-bcmath php-imagick php8.1-xml php8.1-zip

Now we can deactivate the old PHP version (if it’s not already done) and ensure that the newest version is activated.

a2dismod php7.4
a2enmod php8.1

We can also use this command to set the default PHP version, ensuring it will always be used unless specified otherwise. We have the option to either leave it as the default or force it to always prefer our selected version. This however only has an effect on the PHP commands you use on the CLI and is not app specific.

update-alternatives --config php

The last thing we need to do with PHP is change some of the standard settings for Nextcloud. These can be found here:

vim /etc/php/8.1/apache2/php.ini
 
memory_limit = 512M
upload_max_filesize = 500M
post_max_size = 500M

Make sure you restart your services so that all of the configurations take effect and you will be good to go.

systemctl restart apache2

From here, you can proceed to install Nextcloud 26 using the built-in installer and complete the update in a matter of minutes.

Conclusion

And there we have it! Your server is now up to date and ready to take on the world. It’s always recommended to keep your system up to date with the latest versions to benefit from security updates, improved performance, and new features for your applications. With Nextcloud, there are numerous ways to enhance your setup, not limited to PHP versions. Exploring Nextcloud hardening is also a worthwhile endeavor and will be covered in our upcoming series of blog posts. So, stay tuned for the next update from us!

Need help with this topic? Feel free to send us a message or subscribe to our newsletter for more content on the topic.

Subcribe for next article

More articles in Cloud | Tutorials
LUKS Encrypted Storage on OpenStack

LUKS Encrypted Storage on OpenStack

Thoroughly securing your IT landscape has become more and more important over the last couple of years. With an increase in (user) data to be managed, processed, and stored, encryption of this data should be on your agenda towards fully secured IT infrastructure....

Securing ingress-nginx with cert-manager

Securing ingress-nginx with cert-manager

In one of our first tutorials, we showed you how to get started with ingress-nginx on your Kubernetes cluster. As a next step, we will tell you how to go about securing ingress-nginx with cert-manager by creating TLS certificates for your services! What is...

Migrating Servers from VMware to Openstack

Migrating Servers from VMware to Openstack

In this tutorial, we will have a look at migrating servers from VMware to OpenStack. After VMware's recent acquisition by Broadcom, many Cloud Service Providers (CSPs) face termination of their partnership programs with VMware. With no further information publicly...

Mastering Kubernetes with Cilium: Empowering L7 Traffic Control

Mastering Kubernetes with Cilium: Empowering L7 Traffic Control

With the new release of the Cilium CNI on our Kubernetes Service you'll get the ability to filter traffic based on L7 properties. It's very powerful and can help a lot with your services security. In this tutorial, we'll be securing an API endpoint to allow access...

Using Terraform with OpenStack

Using Terraform with OpenStack

Many of you may already be familiar using Terraform with Azure or AWS. Although these may be the most used platforms, there is still a need for variety of other options due to local regulations (GDPR). As our systems are geared towards Open-Source, we will be looking...

Dynamic Inventory – An Ansible and Openstack Lovestory

Dynamic Inventory – An Ansible and Openstack Lovestory

For those of you that may not be too familiar with Ansible, it is a great tool to get started in the world of automation and making your life with configuration management a whole lot easier. In this tutorial we will be going through a basic playbook that you can use...

ReadWriteMany (RWX) with the NFS Ganesha Provisioner

ReadWriteMany (RWX) with the NFS Ganesha Provisioner

Introduction You have the desire that your application needs to scale across multiple nodes for load balancing, but needs access to a common PVC? For this purpose, you need a PVC that is RWX-enabled. As part of our Managed Kubernetes Cluster, it is possible to create...

Resizing Persistent Volumes in Kubernetes

Resizing Persistent Volumes in Kubernetes

You want to resize a PersistentVolume (PV) in Kubernetes? In this tutorial, you'll learn how to do it. If you don't already know what a PV is and how you can create one, you should check out the tutorial Creating Persistent Volumes in Kubernetes first.   Let's...

How to start your NETWAYS Managed Database

How to start your NETWAYS Managed Database

In the first Database tutorial, Sebastian already explained what Vitess is all about and what possibilities it offers you, when running your application compared to an ordinary database. In this tutorial, I would like to explain how easy it is for you to start your...

What is Vitess?

What is Vitess?

Back in 2010 a solution was created to solve the massive MySQL scalability challenges at YouTube - and then Vitess was born. Later in 2018, the project became part of the Cloud Native Computing Foundation and since 2019 it has been listed as one of the graduated...