Rocky Linux 9 comes with PHP 8.0 as default and base package. Even 8.0 is fine to use, but there maybe time you would like to update to latest stable release at hand to test your app. Read on how to upgrade to PHP 8.1 on Rocky Linux 9 the easy way.
If you have installed PHP and other packages following the article below, then proceed with the upgrade. Otherwise you can still install PHP and Apache from it and skip MariaDB, Redis etc if you don’t need them. Or you can add the repository first from this article and then follow the installation article to install PHP. Both scenarios will get you latest PHP 8.1.
Remi repository
First we will add remi repository.
dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm
Update the system.
dnf update
Enable remi:8.1 module
Check what modules are available.
dnf module list php
As our target is PHP 8.1, so we will enable 8.1 module.
dnf module enable php:remi-8.1
Once you do, an e
flag will be added to the module enabled.
Upgrade to PHP 8.1
After enabling the module, you only need to run update command if you have previously installed PHP.
dnf update
But if you have yet to install PHP, you can follow the article link above to do so.