For users of the Hansson IT Nextcloud server, this should help upgrade old versions of PHP.

The following steps have been tested on a successful upgrade from PHP7.2 to PHP 7.4.

Update system and add php7.4 repo

sudo /bin/bash -c 'apt-get install software-properties-common && add-apt-repository ppa:ondrej/php && apt-get update && apt-get upgrade'

Install the most used PHP packages

sudo apt-get install php7.4 php7.4-cli php7.4-common php7.4-mysql php7.4-fpm php7.4-curl php7.4-opcache php7.4-apc libapache2-mod-php7.4 php7.4-mbstring php7.4-xml php7.4-gd php7.4-imagick php7.4-tidy php7.4-xmlrpc php7.4-bz2 php7.4-intl php7.4-json php7.4-imap php7.4-pspell php7.4-xsl php7.4-zip php-memcache php7.4-redis php7.4-smbclient php-pear php-zip

Ensure all previously used PHP modules are upgraded

sudo apt install $(apt list --installed | grep php7.2- | cut -d'/' -f1 | sed -e 's/7.2/7.4/g')

Manually check the PHP default version is changed

sudo update-alternatives --config php

Stop Apache and disable old PHP FPM prior to changes

sudo systemctl stop apache2
sudo systemctl stop php7.2-fpm
sudo systemctl disable php7.2-fpm

Replace FPM socket version in Apache configs

sudo cp /etc/apache2/sites-available/nextcloud_http_domain_self_signed.conf{,.bak}
sudo cp /etc/apache2/sites-available/nextcloud_ssl_domain_self_signed.conf{,.bak}
sudo sed -i -e s/php7.2/php7.4/g /etc/apache2/sites-enabled/nextcloud_http_domain_self_signed.conf
sudo sed -i -e s/php7.2/php7.4/g /etc/apache2/sites-enabled/nextcloud_ssl_domain_self_signed.conf

Move Hansson IT's Nextcloud FPM config into place

sudo cp /etc/php/7.2/fpm/pool.d/nextcloud.conf /etc/php/7.4/fpm/pool.d/nextcloud.conf
sudo sed -i -e s/7.2/7.4/g /etc/php/7.4/fpm/pool.d/nextcloud.conf

Disable unused Apache mods and enable new mods

sudo /bin/bash -c 'a2enmod proxy_fcgi setenvif \
a2enconf php7.4-fpm \
a2dismod php7.2 \
a2dismod php7.2-fpm \
a2dismod php7.4 \
a2dismod mpm_fork \
a2dismod mpm_prefork \
a2enmod mpm_event'

Enable FPM service and restart Apache

sudo systemctl start php7.4-fpm
sudo systemctl enable php7.4-fpm
sudo systemctl start apache2
sudo systemctl enable apache2