Broken Nextcloud after Ubuntu LTS upgrade to php8.1

I have a working Nextcloud on Ubuntu 21.10, However I was recently nagged into upgrading to Ubuntu LTS 22.04 LTS
Upgrade went smoothly, but it appears that php8.1 has been installed, and 8.0 is required. I have tried to manually downgrade to 8.0, Google is all worked out, but I keep hitting dependency problems.
Does anyone know of a step by step downgrade tutorial that can help me downgrade php8.1 to 8.0… I have tried grepping 8.1 removing each package, and replacing with the same 8.0 package…but this feels inelegant, and frankly isn’t working and I am afraid i am going to end up with a system littered with junk
Any help would be valuable

Yes, try searching for how to do this on the forum. You’ll find the answer.

You are missing the required support template. Please fill this form out and edit into your post.

This will give us the technical info and logs needed to help you! Thanks.

I have struggled to find a step by step way of doing this, however having taken ages I have managed it. For any other newbies this is how I did it, and got a working system.
Is it perfect? No
Is it Elegant? No
Did it work for me? Yes
If you have updated Ubuntu 21.10 to 22.4 without realising it will break nextcloud I hope this helps
Obviously YMMV and I have no idea what will happen with the next upgrade, but lets cross that bridge when we get there :grinning:

Remove PHP 8.1
sudo apt-get purge php8.1-apcu php8.1-bcmath php8.1-cli php8.1-common php8.1-curl php8.1-fpm php8.1-gd php8.1-gmp php8.1-igbinary php8.1-imagick php8.1-intl php8.1-ldap php8.1-mbstring php8.1-memcached php8.1-msgpack php8.1-mysql php8.1-opcache php8.1-phpdbg php8.1-readline php8.1-redis php8.1-xml php8.1-zip
Clean up any odds & sods missed
sudo apt-get purge php8.1 && sudo apt-get autoclean && sudo apt-get autoremove
Add Repository for PHP 8.0 and update packages

sudo add-apt-repository ppa:ondrej/php
sudo apt update

Install PHP 8.0
sudo apt-get install php8.0
Install required modules (done in two steps, some duplication)

sudo apt install php8.0 libapache2-mod-php8.0 php8.0-mysql php-common php8.0-cli php8.0-common php8.0-json php8.0-opcache php8.0-readline
sudo apt install imagemagick php-imagick libapache2-mod-php8.0 php8.0-common php8.0-mysql php8.0-fpm php8.0-gd php8.0-curl php8.0-zip php8.0-xml php8.0-mbstring php8.0-bz2 php8.0-intl php8.0-bcmath php8.0-gmp

Start Apache2
sudo systemctl start apache2

1 Like

There is no need to remove php 8.1 you can have multiple php versions installed side by side.

php requirements
after you have installed libapache2-mod-php8.0 and all php8.0 modules you want you can set your preferred php version like so

sudo update-alternatives --config php
sudo a2dismod php8.1
sudo a2enmod php8.0

1 Like

Thank you for that clarification… I am not an IT professional, and this makes things much more elegant.
Can I assume that I could reinstall 8.1, set as per the code and when Nextcloud 24 comes along switch to 8.1 seamlessly, or is there a gotcha?

yes you can have 8.1 installed ready for NC24

just do

sudo update-alternatives --config  php
sudo a2dismod php8.0
sudo a2enmod php8.1
sudo apache2ctl restart

NC 24 is about to be release this week and is compatible with php 8.1. I wouldn’t fiddle around installing other versions, if you want to start right now, there is already the release candidate that can be installed, it should be similar or very similar to the final release and you can easily upgrade.


when upgraded from the previous LTS to ubuntu LTS 22.04 my nc server stopped working. i assume i was on nc 24 (latest stable as of last week).

this is the error i get:

apache2: Syntax error on line 146 of /etc/apache2/apache2.conf: Syntax error on line 3 of /etc/apache2/mods-enabled/php7.4.load: Can't locate API module structure `php7_module' in file /usr/lib/apache2/modules/ /usr/lib/apache2/modules/ undefined symbol: php7_module
Action 'restart' failed.
The Apache error log may have more information.

any clues as to where i should start? it seems i have both 7.4.load and 8.1.load in …/mods-enabled/
i may be totally off here, but does apache somewhere still search for 7.4 instead of 8.1, and that’s the file that needs to be updated?

The 7.4 version is probably from the previous version. Remove the 7.4 version from mods-enabled.

sudo a2dismod php7.4

thank you. that simple command solved it for me and nextcloud is up and running again.

  • ubuntu LTS 22.04, upgraded from ubuntu LTS 20.4.
  • php version 8.1.

Thanks, this fixed my issue with nextcloud 25 after upgrading to Ubuntu 22.04 LTS