Upgrade to PHP 8 on Ubuntu 20.04

Nextcloud Hub II or Nextcloud 23 dropped support for PHP 7.3. Instead of installing or sticking to PHP 7.4 it’s best to upgrade to PHP 8 on Ubuntu 20.04.

Note: Nextcloud currently does not support PHP 8.1, so we will have to install and setup PHP 8.0.

In the default Ubuntu 20.04 repositories the latest stable version you will find is PHP 7.4.

If you have just booted the server, you may need to update(some servers require this) the repositories and upgrade the packages sudo apt update && sudo apt upgrade -y.

Add a PPA to install PHP 8 maintained by a Debian maintainer.

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

Update and upgrade:

sudo apt update && sudo apt upgrade -y

You can also install PHP 8.1 with just replacing the 0 with 1 in the command below.

Install the required packages:

sudo apt install libapache2-mod-php8.0 php8.0 php8.0-gmp php8.0-bcmath php8.0-gd php8.0-mysql php8.0-curl php8.0-mbstring php8.0-intl php8.0-imagick php8.0-xml php8.0-zip php8.0-fpm php8.0-redis php8.0-fileinfo php8.0-apcu

Disable older PHP versions for Apache with:

sudo a2dismod php7.3

Enable Apache PHP 8.0 module:

sudo a2enmod php8.0

You can also completely purge the older versions if you don’t need them.

sudo apt purge php7.3-common

Restart Apache:

sudo systemctl restart apache2

One comment

  1. Many thanks man !
    i upgraded ubuntu from 21.04 to 21.10 and follow your guide (easy peasy and everything was working properly).

    Then upgraded to 22.04 and cron job was not working properly anymore. For those who got error with cache and cron job, check this link : https://help.nextcloud.com/t/occ-wont-run-with-memcache-apcu/119724

    For lazy people :
    1) assure that apc.enable_cli is set to 1 on your php.ini file
    2) “I put apc.enable_cli=1 in /etc/php/{{ php_version }}/mods-available/apcu.ini and it worked. ({{ php_version }} == 7.4/8.0)” —> this did the trick for me and cron was working properly again !

Leave a Reply

Your email address will not be published.