Websites & apps

Install PHP 8.x on AlmaLinux and Rocky Linux with Remi

Enable EPEL and the Remi repository on AlmaLinux or Rocky Linux 8 and 9, choose a PHP module stream, install PHP-FPM with common extensions, and run extra PHP versions side by side.

IntermediateLinux server4 min read

AlmaLinux and Rocky Linux focus on stability, so the PHP versions in their own repositories are often older than what modern apps require. The Remi repository, maintained by a long-time Fedora and PHP packager, provides current PHP builds for these systems. This guide enables it, installs PHP-FPM from a module stream, and adds extra versions alongside when you need more than one.

Before you start

  • A Linux VPS running AlmaLinux or Rocky Linux 8 or 9, with a sudo user. Check your release:
Bash
  cat /etc/redhat-release

Note: Remi supports specific PHP versions for each OS release, and that list changes as versions reach end of life. Run dnf module list php after enabling the repository to see what is offered on your server.

Enable EPEL and the extra repositories

Remi depends on packages from EPEL, which in turn needs the CodeReady Builder (CRB) repository on version 9, called PowerTools on version 8.

AlmaLinux and Rocky Linux 9

Bash
sudo dnf install -y dnf-plugins-core epel-release
sudo dnf config-manager --set-enabled crb
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm

AlmaLinux and Rocky Linux 8

Bash
sudo dnf install -y dnf-plugins-core epel-release
sudo dnf config-manager --set-enabled powertools
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm

Accept the GPG key prompts when dnf asks. They come from the EPEL and Remi repositories you just added.

Choose a PHP module stream

On these systems PHP is delivered as a module with several streams, one per version. List them:

Bash
sudo dnf module list php

You will see the OS streams (for example 8.1 or 8.2) and Remi streams named like remi-8.3 and remi-8.4. Only one stream can be enabled at a time.

Reset any stream that is already enabled, then enable the one you want:

Bash
sudo dnf module reset -y php
sudo dnf module enable -y php:remi-8.3

Install PHP-FPM and extensions

Bash
sudo dnf install -y php-fpm php-cli php-common php-mysqlnd php-gd php-mbstring php-xml php-intl php-opcache php-pecl-zip php-bcmath

Extension package names on these systems differ from Debian. For example, MySQL support is php-mysqlnd, and PECL extensions such as Redis or Imagick are php-pecl-redis (check the exact name with dnf search php-pecl).

Start PHP-FPM and enable it at boot:

Bash
sudo systemctl enable --now php-fpm
php -v

Connect PHP-FPM to your web server

The default pool is /etc/php-fpm.d/www.conf. Its key settings are:

INI
user = apache
group = apache
listen = /run/php-fpm/www.sock
listen.acl_users = apache,nginx
  • Apache (httpd): the package adds /etc/httpd/conf.d/php.conf, which sends .php files to this socket. Restart httpd and PHP works.
  • Nginx: the package adds /etc/nginx/conf.d/php-fpm.conf with an upstream called php-fpm, and /etc/nginx/default.d/php.conf. In your own server blocks, point PHP at the socket directly:
Nginx
  location ~ \.php$ {
      include fastcgi_params;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_pass unix:/run/php-fpm/www.sock;
  }

If only Nginx runs on the server, change user and group in the pool to nginx, so file ownership is consistent. Then restart PHP-FPM.

SELinux in enforcing mode allows the web server to use this socket by default. If your site's files live outside /var/www, label them correctly as explained in SELinux basics.

Run more than one PHP version

The module stream sets the default PHP. For other versions, Remi provides separately named packages that install under /opt/remi, so they do not conflict:

Bash
sudo dnf install -y php82-php-fpm php82-php-cli php82-php-mysqlnd php82-php-gd php82-php-mbstring php82-php-xml php82-php-intl php82-php-opcache
sudo systemctl enable --now php82-php-fpm

Each extra version has its own:

  • Service: php82-php-fpm
  • CLI command: php82
  • Pool config: /etc/opt/remi/php82/php-fpm.d/www.conf
  • php.ini: /etc/opt/remi/php82/php.ini
  • Socket: /var/opt/remi/php82/run/php-fpm/www.sock

Point a site at that socket path to run it on PHP 8.2 while the rest of the server uses the default version.

Check it works

Bash
php -v
php -m | grep -E "mysqlnd|mbstring|Zend OPcache"
systemctl status php-fpm --no-pager
ls -l /run/php-fpm/

The version should match the stream you enabled, the modules should be listed, the service should be active (running) and the socket should exist.

For a web test, create /var/www/html/info.php containing <?php echo PHP_VERSION; and open it in a browser. Delete it right after.

Troubleshooting

  • "Modular dependency problems" or a conflict during install: another stream is still enabled. Run sudo dnf module reset -y php and enable the stream again.
  • epel-release installs but packages are missing: CRB (9) or PowerTools (8) is not enabled. Run the config-manager command for your version.
  • 502 or "File not found" from Nginx: the socket path or SCRIPT_FILENAME is wrong, or the pool's listen.acl_users does not include nginx.
  • Permission denied writing uploads with SELinux on: the folder needs the httpd_sys_rw_content_t label. See Fix SELinux denials.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.