⚠
CentOS 7 reached end-of-life on 30 June 2024. It no longer receives security updates. If you’re still on CentOS 7, plan a migration to AlmaLinux 9 or Rocky Linux 9 – both are free, RHEL-compatible successors. The modern steps are included below.
PHP updates matter for both security and performance – each major version is faster and patches known vulnerabilities. This guide covers how to update PHP on CentOS 7 using the Remi repository (still valid for existing servers), and then the recommended path on AlmaLinux 9 and Rocky Linux 9, which is where new servers should be.
Check Your Current PHP Version
php -v
Update PHP on CentOS 7 (Remi Repository)
CentOS 7’s default repositories ship an old PHP. The Remi repository provides current versions. These steps still work on existing CentOS 7 servers:
1. Install the EPEL and Remi repositories:
sudo yum install -y epel-release yum-utils sudo yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
2. Enable the PHP version you want (example: PHP 8.3):
sudo yum-config-manager --enable remi-php83
3. Install or update PHP and common extensions:
sudo yum install -y php php-cli php-fpm php-mysqlnd php-gd \ php-mbstring php-xml php-curl php-zip
4. Restart your web service and verify:
sudo systemctl restart php-fpm httpd php -v
Recommended: PHP on AlmaLinux 9 / Rocky Linux 9
On a modern RHEL-family system, PHP is managed through DNF modules plus Remi. This is the setup for new servers:
5. Add EPEL and Remi:
sudo dnf install -y epel-release sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm
6. Reset and enable the PHP module stream:
sudo dnf module reset php -y sudo dnf module enable php:remi-8.3 -y
7. Install PHP and extensions, then verify:
sudo dnf install -y php php-fpm php-cli php-mysqlnd \ php-gd php-mbstring php-xml php-curl php-zip sudo systemctl restart php-fpm php -v
Always test your application after a PHP upgrade – a major version jump (for example 7.4 to 8.3) can require small code changes. Back up first.
FAQ
Q: Is CentOS 7 still supported? – No. CentOS 7 reached end-of-life on 30 June 2024 and no longer receives updates. Migrate to AlmaLinux 9 or Rocky Linux 9.
Q: How do I update PHP on CentOS 7? – Install the EPEL and Remi repositories, enable the desired version (e.g. remi-php83), then install/update PHP and restart php-fpm.
Q: What should I migrate to from CentOS 7? – AlmaLinux 9 or Rocky Linux 9 – both are free, community-supported, RHEL-compatible successors to CentOS.