Hello all, this came in handy the other day for nextcloud so I figured I would put a quick post about it out. Let's say, you want a PHP 8.0 to be used in Apache. Here is what I did to do that specific option. Also, it is what I would recommend if you are using NextCloud.

Add Needed Repository

Below, it will setup the apt repository to get the latest available PHP version that are compatible with Debian.

sudo apt update

sudo apt install -y lsb-release ca-certificates apt-transport-https software-properties-common gnupg2

KEYRING=/etc/apt/trusted.gpg.d/sury-keyring.gpg

curl -fsSL  https://packages.sury.org/php/apt.gpg| sudo gpg --dearmor -o $KEYRING


echo "deb [signed-by="$KEYRING"] https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/sury-php.list

Update and Install Specific Version of PHP.

sudo apt update && sudo apt upgrade
Currently, Nextcloud only supports up to PHP 8.0 so if installing on NextCloud do not go over PHP 8.0 or it will fail to load. Nextcloud Hub II (23.0.12). Oh, there is a new version of nextcloud out at 24 so I will have to try that and update post as needed.

Next, Install PHP specific packages. Below, are the ones I used in NextCloud.

sudo apt install php-imagick php8.0-fpm php8.0-common php8.0-gd php8.0-imap php8.0-mysql php8.0-curl php8.0-zip php8.0-xml php8.0-mbstring php8.0-bz2 php8.0-intl php8.0-gmp php8.0-redis php8.0-imagick php8.0-gmp php8.0-bcmath

Configure Apache

Below configures Apache to use 8.0 fpm. As shown, I was using 8.1 so adjust according to needs to disable modules of the specific PHP that is not wanted and enable modules for correct versions as needed.
sudo a2dismod php8.1
sudo a2dismod mpm_prefork
sudo a2disconf php8.1-fpm
sudo a2enmod mpm_event
# optional in case its enabled
sudo a2enmod proxy
# optional in case its enabled
sudo a2enmod proxy_fcgi
sudo a2enconf php8.0-fpm
sudo systemctl restart php8.0-fpm
sudo systemctl restart apache2
# manually set php version for CLI
sudo update-alternatives --set php /usr/bin/php8.0
sudo update-alternatives --set phar /usr/bin/phar8.0
sudo update-alternatives --set phar.phar /usr/bin/phar.phar8.0

sudo systemctl status php8.0-fpm
sudo systemctl stop php8.1-fpm
sudo systemctl mask php8.1-fpm

Leave a Reply

Your email address will not be published. Required fields are marked *