Upgrade or Install PHP 8.x on Debian running Apache2
1. List existing PHP packages to packages.txt which can be referred anytime.
dpkg -l | grep php | tee packages.txt
2. Updating Debian as root
#apt update #apt upgrade -y && reboot
2. Add SURY PHP PPA Repository
SURY is a third-party repository that offers current PHP versions for Debian GNU/Linux, which is added as root.
#apt -y install lsb-release apt-transport-https ca-certificates wget #wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg #echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list #apt update -y
3. Installing PHP 8.x on Debian
#apt -y install php8.2 #update-alternatives --set php /usr/bin/php8.2
More than one PHP version can be installed on the system, run update-alternatives –set php [version] to enable a Version.
4. Install Important Web Modules for PHP 8.2 on Debian
#apt -y install libapache2-mod-php8.2 php8.2-mysql php8.2-gd -y #systemctl restart apache2
5. Module for WordPress server
#apt install php8.2-gd php8.2-mbstring php8.2-xml php8.2-xmlrpc php8.2-curl
6.Check the current PHP version
#php -v PHP 8.2.14 (cli) (built: Dec 21 2023 20:21:17) (NTS) Copyright (c) The PHP Group Zend Engine v4.2.14, Copyright (c) Zend Technologies with Zend OPcache v8.2.14, Copyright (c), by Zend Technologies
7. Activate PHP 8.2
#a2dismod php7.3 #a2enmod php8.2 #systemctl apache2 restart
Optional Remove the old version of PHP
#apt-get purge --auto-remove php7*