Upgrading from PHP 7 to PHP 8

Prerequisites

  • Open a terminal window with the root user and enter the following command:
php --version

You will get an answer similar to the following:

PHP 7.4.29 (cli) (built: Apr 12 2022 10:55:38) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

Rocky Linux 8/AlmaLinux 8/RHEL 8

Updating to PHP 8.0

  • Configure the repositories:
dnf module reset php -y
dnf -y module enable php:remi-8.0
  • Install PHP:
dnf install -y \
php php-mcrypt php-cli php-gd \
php-curl php-session php-mysqlnd \
php-ldap php-zip php-zlib php-fileinfo \
php-gettext php-snmp php-mbstring \
php-pecl-zip php-xmlrpc \
php-xml php-yaml
  • Restart php-fpm systemctl restart php-fpm.
  • Verify the version installed: php -v.

Updating to PHP 8.2

dnf module reset php -y
dnf -y module enable php:remi-8.2
 
dnf install -y \
php php-mcrypt php-cli php-gd \
php-curl php-session php-mysqlnd \
php-ldap php-zip php-zlib php-fileinfo \
php-gettext php-snmp php-mbstring \
php-pecl-zip php-xmlrpc \
php-xml php-yaml
 
systemctl restart php-fpm

Ubuntu server 22.04

dpkg -l | grep php | tee packages.txt
# Remove old PHP
# When upgrading from older PHP version:
a2disconf php8.1-fpm 2> /dev/null
a2disconf php8.0-fpm 2> /dev/null
dpkg -l | grep php | awk '{print $2}' | xargs apt -y purge
 
 
## Define new php
export DEBIAN_FRONTEND=noninteractive
export NEEDRESTART_SUSPEND=1
export PHPVER="8.2"
add-apt-repository ppa:ondrej/php 
apt update
apt install -y php$PHPVER php$PHPVER-fpm php$PHPVER-common \
                    php$PHPVER-cli libapache2-mod-fcgid apache2 \
                    php$PHPVER-bz2 php$PHPVER-mbstring php$PHPVER-intl  php$PHPVER-mcrypt \
                    php$PHPVER-gd  php$PHPVER-curl  php$PHPVER-mysql php$PHPVER-ldap \
                    php$PHPVER-fileinfo php$PHPVER-gettext php$PHPVER-snmp php$PHPVER-mbstring \
                    php$PHPVER-zip php$PHPVER-xmlrpc php$PHPVER-xml php$PHPVER-yaml
 
a2enmod proxy_fcgi setenvif
a2enconf php$PHPVER-fpm
 
## Prepare php config
rm -f /etc/php.ini
ln -s /etc/php/$PHPVER/fpm/php.ini /etc/
sed --follow-symlinks -i -e "s/^max_input_time.*/max_input_time = -1/g" /etc/php.ini
sed --follow-symlinks -i -e "s/^max_execution_time.*/max_execution_time = 0/g" /etc/php.ini
sed --follow-symlinks -i -e "s/^upload_max_filesize.*/upload_max_filesize = 800M/g" /etc/php.ini
sed --follow-symlinks -i -e "s/^memory_limit.*/memory_limit = 800M/g" /etc/php.ini
sed --follow-symlinks -i -e "s/.*post_max_size =.*/post_max_size = 800M/" /etc/php.ini
sed --follow-symlinks -i -e "s/^disable_functions/;disable_functions/" /etc/php.ini
 
systemctl enable php$PHPVER-fpm --now
systemctl restart php$PHPVER-fpm
systemctl restart apache2

CentOS 7

The end-of-life of the CentOS 7 operating system is June 2024.

Upgrading CentOS 7 to PHP 8.0

  • Configure the repositories:
yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum -y install yum-utils
yum-config-manager --disable 'remi-php*'
yum-config-manager --enable remi-php80
  • Install PHP 8 and its dependencies:
yum install -y \
 php-mcrypt php-cli php-gd php-curl php-session \
 php-mysqlnd php-ldap php-zip php-zlib php-fileinfo \
 php-gettext php-snmp php-mbstring php-pecl-zip \
 php-xmlrpc php-xml php-yaml mod_php
  • Restart the web server: systemctl restart httpd .
  • Verify the version installed with: php -v .

Upgrading CentOS 7 to PHP 8.2

  • Configure the repositories:
yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum -y install yum-utils
yum-config-manager --disable 'remi-php*'
yum-config-manager --enable remi-php82
  • Install PHP 8 and its dependencies:
yum install -y \
 php-mcrypt php-cli php-gd php-curl php-session \
 php-mysqlnd php-ldap php-zip php-zlib php-fileinfo \
 php-gettext php-snmp php-mbstring php-pecl-zip \
 php-xmlrpc php-xml php-yaml mod_php
  • Restart the web server: systemctl restart httpd .
  • Verify the version installed with: php -v .

RHEL 7