Skip to content

How to Install PHP 8.5 & 8.4 on RHEL, Rocky & AlmaLinux 9

Install PHP on RHEL 9, Rocky Linux, AlmaLinux or CentOS Stream 9: PHP 8.4 from AppStream, or 8.5 to 7.4 from Remi. Covers extensions, PHP-FPM and switching.

Steps
9
Category
PHP
Covers
RHEL
On this page 9 steps

PHP still powers a large part of the web, from WordPress, Drupal and Magento to Laravel and Symfony applications. On Red Hat Enterprise Linux 9 and its rebuilds, you have two good ways to install it: the AppStream repository that comes with the system, and the Remi repository, which provides every PHP version from 8.5 down to 7.4.

This guide shows both methods on RHEL 9, Rocky Linux 9, AlmaLinux 9 and CentOS Stream 9. The commands are the same on all four, apart from enabling one extra repository on RHEL. You will also install extensions, connect PHP to Apache or Nginx through PHP-FPM, run several PHP versions side by side, and switch between them.

Updated November 2026: the guide now covers PHP 8.5 and 8.4, the AppStream module streams, and running multiple PHP versions. It replaces our separate CentOS Stream 9 guide.

Running version 10? See How to Install PHP on RHEL 10, which covers the new package layout.

Last tested: November 2026 on Rocky Linux 9.9, AlmaLinux 9.9 and CentOS Stream 9.

Which PHP Version Should You Install?

Each PHP branch gets two years of active support and then two more years of security-only fixes. This is where each branch stands as of November 2026, and where to get it on RHEL 9:

VersionSecurity support untilAvailable from
PHP 8.6Dec 31, 2030Remi (remi-8.6, release candidate builds for now)
PHP 8.5Dec 31, 2029Remi. Best choice for new projects
PHP 8.4Dec 31, 2028AppStream module or Remi
PHP 8.3Dec 31, 2027AppStream module or Remi
PHP 8.2Dec 31, 2026AppStream module or Remi. Reaches end of life soon
PHP 8.1, 8.0, 7.4EndedAppStream (8.1, 8.0) or Remi. Legacy code only

One detail catches many people out: a plain sudo dnf install php on RHEL 9 installs PHP 8.0, the non-modular default that reached end of life upstream in 2023. Always enable the module stream you want first, as shown below. For the latest point releases, see the PHP release tracker.

Prerequisites

  • A system running RHEL 9, Rocky Linux 9, AlmaLinux 9 or CentOS Stream 9
  • A user account with sudo privileges
  • An internet connection (and an active subscription on RHEL)

Step 1 of 9Update Your System

Update the installed packages before you add repositories or install PHP:

sudo dnf update -y

If the update installed a new kernel, reboot before continuing.

Step 2 of 9Option A: Install PHP 8.4 from AppStream

If PHP 8.4 or an older branch is enough, you don’t need any third-party repository. AppStream provides PHP as module streams. List them:

dnf module list php

On a current RHEL 9 system you will see the streams 8.1, 8.2, 8.3 and 8.4. Enable the one you need and install PHP:

sudo dnf module enable php:8.4 -y
sudo dnf install php php-cli php-fpm php-common -y

Packages from AppStream are supported by your distribution vendor for the life of the module stream. Continue with Step 4, or use Option B if you need PHP 8.5.

Step 2 of 9Option B: Add the EPEL and Remi Repositories

The Remi repository is maintained by Remi Collet, who also maintains PHP packaging in Fedora and RHEL. It provides every PHP version from 8.6 down to 7.4 and usually has new point releases within days. Remi depends on EPEL, and EPEL needs the CodeReady Builder (CRB) repository.

Enable EPEL and CRB for your distribution:

  • Rocky Linux 9 and AlmaLinux 9:
    sudo dnf install epel-release -y
    sudo dnf config-manager --set-enabled crb
    
  • CentOS Stream 9:
    sudo dnf install epel-release epel-next-release -y
    sudo dnf config-manager --set-enabled crb
    
  • RHEL 9:
    sudo subscription-manager repos --enable codeready-builder-for-rhel-9-$(arch)-rpms
    sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm -y
    

If dnf config-manager isn’t found, install it with sudo dnf install dnf-plugins-core -y. Then install the Remi release package:

sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm -y

Adding Remi doesn’t change anything that is already installed. It adds the remi-X.Y module streams next to the AppStream ones.

Step 3 of 9Install a Specific PHP Version from Remi

List all available streams. With Remi enabled, the list includes remi-7.4 up to remi-8.6:

dnf module list php

Reset the PHP module first, so no other stream stays enabled, then enable the version you need and install it:

  • PHP 8.5 (recommended)
    sudo dnf module reset php -y
    sudo dnf module enable php:remi-8.5 -y
    sudo dnf install php php-cli php-fpm php-common -y
    
  • PHP 8.4
    sudo dnf module reset php -y
    sudo dnf module enable php:remi-8.4 -y
    sudo dnf install php php-cli php-fpm php-common -y
    
  • PHP 8.3
    sudo dnf module reset php -y
    sudo dnf module enable php:remi-8.3 -y
    sudo dnf install php php-cli php-fpm php-common -y
    
  • PHP 7.4 (legacy applications only)
    sudo dnf module reset php -y
    sudo dnf module enable php:remi-7.4 -y
    sudo dnf install php php-cli php-fpm php-common -y
    

The remi-8.6 stream currently ships release candidate builds. Use it for testing, and switch to it for production once the final 8.6 packages land.

Step 4 of 9Verify the Installation

Check the installed version:

php -v

PHP 8.5.12 (cli) (built: Oct 19 2026 17:02:46) (NTS gcc x86_64)

The output also lists Zend OPcache, which is built into PHP 8.5.

Step 5 of 9Install PHP Extensions

Extensions use the same names for every version, because the enabled module stream decides which version you get. This set covers what WordPress, Laravel, Symfony and similar projects expect:

sudo dnf install php-{mysqlnd,pgsql,gd,mbstring,xml,zip,intl,bcmath,soap} -y

List the loaded modules to verify them:

php -m
  • php-mysqlnd and php-pgsql are the database drivers. Install only the one your database uses.
  • PECL extensions are packaged with a php-pecl- prefix, for example php-pecl-redis, php-pecl-imagick or php-pecl-apcu. Search with dnf search php-pecl.
  • OPcache: for PHP 8.4 and older, install php-opcache. In PHP 8.5 OPcache is built in, so don’t install that package; dnf would offer the old PHP 8.0 build from AppStream instead.

Step 6 of 9Use PHP with Apache or Nginx

On RHEL 9 both web servers run PHP through PHP-FPM. The php-fpm package already includes the configuration for both of them, so very little manual work is needed.

Apache (httpd)

Install Apache if you haven’t already (see how to install Apache (httpd) for details), then start both services:

sudo dnf install httpd -y
sudo systemctl enable --now php-fpm httpd

The file /etc/httpd/conf.d/php.conf passes every .php file to the PHP-FPM socket /run/php-fpm/www.sock. No further configuration is needed.

Nginx

Install Nginx and start both services:

sudo dnf install nginx -y
sudo systemctl enable --now php-fpm nginx

The php-fpm package adds /etc/nginx/conf.d/php-fpm.conf, which defines an upstream named php-fpm, and /etc/nginx/default.d/php.conf, which sends PHP requests to it. The default server already includes the default.d directory. For your own server blocks, add the same line inside the server { } block:


server {
    listen 80;
    server_name example.com;
    root /var/www/example.com;
    index index.php index.html;

    include /etc/nginx/default.d/*.conf;
}

The socket allows both the apache and nginx users (listen.acl_users = apache,nginx in /etc/php-fpm.d/www.conf), so Nginx can connect without permission changes. Test and reload Nginx:

sudo nginx -t
sudo systemctl reload nginx

Firewall and SELinux

Open HTTP and HTTPS in firewalld:

sudo firewall-cmd --permanent --add-service={http,https}
sudo firewall-cmd --reload

SELinux stays enabled. If your application connects to a database on another server, allow it explicitly, because SELinux blocks network connections from the web server by default:

sudo setsebool -P httpd_can_network_connect_db 1

Step 7 of 9Run Multiple PHP Versions Side by Side

The module stream sets the one “main” PHP version. Remi also provides parallel packages with a version prefix, such as php84, php83 or php74. They install into /opt/remi and don’t conflict with the main version. For example, add PHP 8.4 next to a main PHP 8.5:

sudo dnf install php84-php-cli php84-php-fpm php84-php-mysqlnd -y
php84 -v

Start its own PHP-FPM service:

sudo systemctl enable --now php84-php-fpm

This service listens on /var/opt/remi/php84/run/php-fpm/www.sock and reads its configuration from /etc/opt/remi/php84/. Point a site at it to run that site on PHP 8.4, for example in Nginx with fastcgi_pass unix:/var/opt/remi/php84/run/php-fpm/www.sock;, or in an Apache virtual host with a SetHandler "proxy:unix:/var/opt/remi/php84/run/php-fpm/www.sock|fcgi://localhost" line.

Switch the Main PHP Version

To move the main installation to another version, for example from 8.4 to 8.5, reset the module, enable the new stream and let dnf replace the packages:

sudo dnf module reset php -y
sudo dnf module enable php:remi-8.5 -y
sudo dnf distro-sync -y
sudo systemctl restart php-fpm

The same commands work in the other direction, for example back to php:remi-7.4 for a legacy application. Test your application after each switch.

Step 8 of 9Adjust php.ini Settings

The main PHP installation reads /etc/php.ini, plus the extension files in /etc/php.d/. Confirm which files are loaded:

php --ini

Edit the main file:

sudo nano /etc/php.ini

These are sensible starting values for a typical web application:


memory_limit = 256M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 120
date.timezone = UTC

Restart PHP-FPM so the website picks up the changes:

sudo systemctl restart php-fpm

Parallel versions have their own files, for example /etc/opt/remi/php84/php.ini and the php84-php-fpm service.

Step 9 of 9Test PHP in the Browser

Create a test file in the web root. Apache uses /var/www/html; the default Nginx server uses /usr/share/nginx/html:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Open http://your-server-ip/info.php in a browser. The page shows the PHP version, the Server API (FPM/FastCGI) and the loaded extensions. Delete the file when you are done, because it reveals details about your server:

sudo rm /var/www/html/info.php

Next, most PHP projects need Composer. See how to install Composer on RHEL-based systems.

Uninstall PHP

Remove the main PHP packages and reset the module stream:

sudo dnf remove 'php*' -y
sudo dnf module reset php -y

Remove a parallel version separately, for example with sudo dnf remove 'php84-*' -y. To remove the Remi repository as well, run sudo dnf remove remi-release -y.

Troubleshooting

dnf installs PHP 8.0 instead of the version you want

No module stream was enabled, so dnf used the non-modular AppStream default. Run dnf module list php, then enable the right stream (Step 2 or Step 3) and run sudo dnf distro-sync -y.

Modular dependency problems or conflicting streams

Only one PHP stream can be enabled at a time. Run sudo dnf module reset php -y before you enable another stream.

502 Bad Gateway or “File not found” with Nginx

Check that PHP-FPM is running with systemctl status php-fpm, and that your server block includes /etc/nginx/default.d/*.conf or points fastcgi_pass at the right socket. If you serve files outside /var/www or /usr/share/nginx, SELinux may block access. Restore the right context with sudo restorecon -Rv /path/to/site, or label a custom path with semanage fcontext.

Conclusion

You now have PHP running on RHEL 9, Rocky Linux 9, AlmaLinux 9 or CentOS Stream 9. Use the AppStream module streams when PHP 8.4 or older is enough and you want vendor-supported packages, and the Remi repository for PHP 8.5, early access to 8.6, or legacy versions. With parallel php84-style packages and separate PHP-FPM services, one server can host applications that need different PHP versions.

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top