Upgrade PHP 7 to PHP 8 on CentOS 8 Stream

As of November 28th, 2022 PHP 7 is no longer supported by the PHP community. Which means it will no longer receive security updates or enhancements of any kind. Upgrading to PHP 8.0 or 8.1 is essential to stay on top of new features and most importantly, the security of your system. Here’s how to upgrading using CentOS 8 Stream. However, you’ll be able to apply these same steps to any “dnf” managed RPM system.

Step 1 – Update Your System

The first thing you’ll want to do is make sure your entire system is generally update to date:

derek@codes $ dnf update

Step 2 – Install the EPEL Release Package

This will give you access to the latest updates provided by the CentOS community:

derek@codes $ dnf install epel-release

Step 3 – View Available PHP Modules

See what options you have on your system:

derek@codes $ dnf module list php

The result of this command will look something like this. You’ll want to be sure you an upgrade is available before we start removing things in the next step.

php                              7.2 [d]                             common [d], devel, minimal                          
php                              7.3                                 common [d], devel, minimal                           
php                              7.4 [e]                             common [d], devel, minimal                           
php                              8.0                                 common [d], devel, minimal

Step 4 – Remove PHP 7

Now remove all references to PHP. Keep a copy of the list of modules that you’re removing. You’ll want to install those again in Step 7.

derek@codes $ dnf remove php php-fpm php-*

Step 5 – Reset The PHP Module Selection

This clears the current PHP 7 selection:

derek@codes $ dnf module reset php

Step 6 – Select the PHP 8 Module

This enables the PHP 8 Module.

derek@codes $ dnf module enable php:8.0

Step 7 – Install PHP 8

Now comes the fun part of installing PHP 8:

derek@codes $ dnf install php php-devel

Also, be sure to install any of the specific modules you noted in Step 4.

derek@codes $ dnf install php-[all the modules you need]

Step 8 – Restart Apache & PHP-FPM

You’re all set to restart Apache and PHP-FPM if you’re using it:

derek@codes $ systemctl restart httpd
derek@codes $ systemctl restart php-fpm
Share via
Copy link
Powered by Social Snap