AlmaLinux

Install PHP 8.4 on Rocky Linux 10 / 9 and AlmaLinux 10 / 9

Rocky Linux 10 and AlmaLinux 10 do not need a third-party repository for PHP 8.4 any more. AppStream carries a parallel set of php8.4 packages next to the default PHP 8.3. Rocky Linux 9 and AlmaLinux 9 still do, because their AppStream default is the long-unsupported PHP 8.0 and its module streams stop at 8.3, so PHP 8.4 comes from the Remi repository there.

Original content from computingforgeeks.com - post 74938

This guide covers both families. You will install PHP 8.4, prove the build carries the PHP2Shell fix, then wire PHP-FPM to Apache or Nginx with firewalld and SELinux left on. On the 10 series we’d run the AppStream packages and skip Remi unless you need 8.5 or quick branch switches. Every step below was run on Rocky Linux 10.2 and Rocky Linux 9.8 with SELinux enforcing in November 2026, and AlmaLinux uses the same package names and repositories but was not run separately this time.

Prerequisites

The steps assume a fresh minimal server you can reach over SSH. Nothing here needs a desktop, and the web server is installed along the way:

  • Rocky Linux or AlmaLinux, 10 or 9 series
  • A user with sudo rights
  • 1 GB RAM and 10 GB free disk as a lab floor
  • Outbound HTTPS to the distro mirrors and rpms.remirepo.net

For production, size RAM by PHP-FPM workers rather than by PHP itself. Each worker of a typical CMS sits at 30 to 50 MB, so 2 GB comfortably carries 20 to 30 workers next to the web server and leaves the database on its own host.

Pick the PHP source for your release

What AppStream offers is the whole decision, and it differs between the two families. Check it before you add any repository.

dnf -q list --available php php8.4 php8.4-cli

On the 10 series, two branches come back from AppStream, and dnf module list php finds nothing because there’s no PHP module there at all:

dnf list showing php 8.3.36 and php8.4 8.4.27 in Rocky Linux 10 AppStream with no php module

The 9 series answers differently. Its plain php package is 8.0.30, a branch the PHP project stopped supporting on 26 November 2023, and three module streams sit on top of it. Nothing in that list reaches 8.4:

  • php 8.0.30, the non-modular default
  • php:8.1, php:8.2 and php:8.3 module streams

So the 9 series takes Remi for this branch, the same route our earlier PHP 8.4 guide for Rocky Linux 9 used, and the table maps each release to the source this guide uses.

ReleaseAppStream defaultPHP 8.4 from
Rocky Linux 10, AlmaLinux 10php 8.3AppStream php8.4 (or Remi)
Rocky Linux 9, AlmaLinux 9php 8.0, modules 8.1 to 8.3Remi php:remi-8.4

If PHP 8.3 is enough for your application on the 10 series, sudo dnf install -y php php-cli php-fpm plus the extensions you need is the whole install, and you can jump to the PHP2Shell check. For the 8.5 branch on the 10 series, follow the PHP 8.5 guide for Rocky Linux and AlmaLinux instead, and for a tour of every AppStream and Remi option see installing PHP on AlmaLinux, Rocky Linux and RHEL.

Install PHP 8.4 from AppStream

This path is for Rocky Linux 10 and AlmaLinux 10 only. The php8.4 packages ship the same binaries and config paths as the default php 8.3 packages, so they conflict. If 8.3 is already installed, dnf refuses until you pass --allowerasing, which removes 8.3 in the same transaction. On a fresh server the flag changes nothing.

sudo dnf install -y --allowerasing php8.4 php8.4-cli php8.4-fpm php8.4-mysqlnd php8.4-gd php8.4-mbstring php8.4-xml php8.4-pecl-zip php8.4-opcache php8.4-bcmath php8.4-intl php8.4-soap

Two names differ from the familiar list, so copy the command as it is rather than prefixing your usual one:

  • no php8.4-curl, cURL is built into php8.4-common
  • zip comes from php8.4-pecl-zip

On our Rocky box with 8.3 installed first, the swap removed 14 packages and installed 14. Asking dnf for the old php-cli afterwards shows the same conflict from the other side.

php8.4-cli conflicts with php-cli 8.3 on Rocky Linux 10 and php --version reports PHP 8.4.27

The binary is still php, the service is still php-fpm, and config stays in /etc/php.ini and /etc/php-fpm.d/, so every later section applies unchanged. Extensions you add later carry the prefix too, so LDAP support is php8.4-ldap, not php-ldap. An edited php.ini survives the swap, and the 8.4 default lands next to it as /etc/php.ini.rpmnew. Diff the two, because an 8.3 file can still set options 8.4 deprecates, such as session.sid_length.

Install PHP 8.4 from Remi

Remi is the only PHP 8.4 source on the 9 series and an option on the 10 series. It needs EPEL and the CRB repository for libraries some extensions link against. The packages hide behind a module stream, so adding the repo changes nothing until you enable php:remi-8.4.

On Rocky Linux 9 and AlmaLinux 9

Enable CRB, install EPEL, then add the release package for EL9 straight from Remi.

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

Our run installed remi-release-9.8-1.el9.remi, and the repo list then showed Remi’s modular and safe repositories next to EPEL and CRB. Reset the PHP module so no AppStream stream stays pinned, then enable Remi’s 8.4 stream.

sudo dnf module reset php -y
sudo dnf module enable php:remi-8.4 -y

Now install PHP with the extensions most web apps want. With the stream enabled, the unprefixed names resolve to Remi’s builds.

sudo dnf install -y php php-cli php-fpm php-mysqlnd php-gd php-mbstring php-xml php-curl php-zip php-opcache php-bcmath php-intl php-soap

On web02 the whole 9 series path ran from the AppStream default to Remi’s 8.4. Look for [e] next to remi-8.4 and the Built by Remi's RPM repository line, which prove the packages did not come from AppStream.

Rocky Linux 9 AppStream php 8.0.30 and Remi php remi-8.4 module stream enabled with PHP 8.4.27 installed

The install also pulled in php-sodium as a weak dependency and httpd-core with its config files. Apache stays disabled until you enable it, so it will not fight Nginx for port 80.

On Rocky Linux 10 and AlmaLinux 10

The steps match, with the EL10 release package. EPEL and CRB go first, then Remi.

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

If any PHP from AppStream is installed, remove it first. Use the glob rather than a list of names, because the php8.4 packages do not match php php-cli php-common and would otherwise stay behind and conflict. That removal is where tuned servers lose their settings. When we edited pm.max_children and memory_limit first and then ran it, dnf printed this:

warning: /etc/php-fpm.d/www.conf saved as /etc/php-fpm.d/www.conf.rpmsave
warning: /etc/php.ini saved as /etc/php.ini.rpmsave

Remi’s packages then laid down stock files, so the pool was back at 50 children and PHP at 128M. Only unowned drop-ins such as /etc/php.d/99-opcache-tuning.ini stayed in place. The same run also listed httpd, httpd-core, httpd-filesystem and httpd-tools under “Removing unused dependencies”, because the AppStream PHP pulls Apache in as a weak dependency. So leave out -y on the removal and read the transaction before you answer it.

sudo dnf remove 'php*'
sudo dnf module reset php -y
sudo dnf module enable php:remi-8.4 -y
sudo dnf install -y php php-cli php-fpm php-mysqlnd php-gd php-mbstring php-xml php-curl php-zip php-opcache php-bcmath php-intl php-soap

Removing php-fpm also disables its unit, so run sudo systemctl enable --now php-fpm again once the Remi build is in. If Apache served your site, reinstall it and switch it back on, because the reinstalled unit comes back disabled and inactive. An edited httpd.conf gets the same .rpmsave treatment.

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

Then compare the saved PHP files with the new ones and carry your edits over by hand.

sudo diff /etc/php-fpm.d/www.conf.rpmsave /etc/php-fpm.d/www.conf
sudo diff /etc/php.ini.rpmsave /etc/php.ini

Do not copy the old php.ini back whole. Ours still carried session.sid_length = 26, and PHP 8.4 deprecates changing that setting, which is why the 8.4 file no longer sets it. The www.conf diff was only our one line. Once your edits are back, run sudo php-fpm -t and restart php-fpm so they take effect. A version check confirms the source.

php --version

The build line names Remi rather than Rocky or AlmaLinux:

PHP 8.4.27 (cli) (built: Oct 19 2026 14:38:59) (NTS gcc x86_64)
Copyright (c) The PHP Group
Built by Remi's RPM repository <https://rpms.remirepo.net/> #StandWithUkraine #NoAI
Zend Engine v4.4.27, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.27, Copyright (c), by Zend Technologies

Whichever source you picked, check the package release against PHP2Shell before the server takes traffic.

Check the build for PHP2Shell

PHP2Shell is the name for CVE-2026-109618 and CVE-2026-109619, two unauthenticated remote code execution bugs that the PHP project fixed on 21 October 2026 in 8.5.12, 8.4.27, 8.3.36 and 8.2.35 (see the PHP security advisory). Rocky’s EL10 and Remi’s changelogs just say “rebase to 8.4.27” or “Update to 8.4.27” without the CVE IDs, so the package release is your check:

rpm -qa 'php*-common'

Compare the result with the first fixed build for your source. Anything at that release or newer is patched.

SourceFirst patched package
EL10 AppStream php8.4, Rockyphp8.4-common-8.4.27-1.el10_2
EL10 AppStream php8.4, AlmaLinuxphp8.4-common-8.4.24-1.el10_2.alma.1
EL10 AppStream php (8.3), Rockyphp-common-8.3.36-1.el10_2
EL10 AppStream php (8.3), AlmaLinuxphp-common-8.3.33-1.el10_2.alma.1
EL9 AppStream php (8.0), AlmaLinuxphp-common-8.0.30-8.el9_8.alma.1
EL9 AppStream php:8.1, AlmaLinuxphp-common-8.1.32-1.module_el9.8.0+326+528679fc.alma.1
EL9 AppStream php:8.2, AlmaLinuxphp-common-8.2.33-1.module_el9.8.0+327+37dfd4b4.alma.1
EL9 AppStream php:8.3, AlmaLinuxphp-common-8.3.33-1.module_el9.8.0+328+1fdeb728.alma.1
EL9 AppStream php (8.0), Rockyphp-common-8.0.30-8.el9_8.1
EL9 AppStream php:8.3, Rockyphp-common-8.3.36-1.module+el9.8.0+40396+4e680bb7
EL9 AppStream php:8.2, Rockyphp-common-8.2.35-1.module+el9.8.0+40395+2f706e64
Remi php:remi-8.4, EL10php-common-8.4.27-1.module_php.8.4.el10.remi
Remi php:remi-8.4, EL9php-common-8.4.27-1.module_php.8.4.el9.remi

The 8.0 row surprised us. Upstream stopped releasing 8.0 in 2023, yet the 8.0.30-8.el9_8.1 build carries a backport, and rpm -qp --changelog on the downloaded package lists CVE-2026-109618, CVE-2026-109619 under “Avoid state corruption via bailout”. Rocky’s php:8.1 stream has no row because it has no fix. On 13 November Rocky still offered only the unpatched 8.1.32, so a Rocky 9 server on that stream should move to Remi’s 8.4 or to php:8.3 now.

AlmaLinux shipped backported builds with an .alma.1 suffix before the upstream rebase landed, so on AlmaLinux the suffix matters more than the version number. Read the AlmaLinux rows, not the Rocky ones: el9_8.alma.1 sorts below Rocky’s el9_8.1, so a Rocky row would call a patched AlmaLinux build old. On AlmaLinux 10 the backported php-common and php8.4-common changelogs also name the CVEs, which gives you a direct check. The query names both packages, and grep drops the line for whichever one is not installed.

rpm -q --changelog php-common php8.4-common | grep CVE-2026-10961

On AlmaLinux 9 we have not checked the changelog text, so compare rpm -q php-common with the AlmaLinux 9 rows of the table instead.

If your release is older than the table, upgrade every PHP package and restart PHP-FPM yourself once dnf finishes. The php-fpm scriptlet restarts the service partway through the transaction, before every extension is replaced, so only your own restart guarantees the patched code is the code serving requests.

sudo dnf upgrade -y 'php*'
sudo systemctl restart php-fpm
systemctl show -p ActiveEnterTimestamp php-fpm

When dnf says there is nothing to upgrade but the version is still old, your mirror may be behind. Run dnf repoinfo appstream | grep Repo-updated and compare the date with 21 October. A Rocky mirror we hit in October lagged by a day, and pointing AppStream at the primary server for one transaction fixed it. That URL is for x86_64 on the 10 series, so change both parts to match your server.

sudo dnf upgrade -y --setopt=appstream.mirrorlist= --setopt=appstream.baseurl=https://dl.rockylinux.org/pub/rocky/10/AppStream/x86_64/os/ 'php*'

For checks on other stacks and the advisory’s background, see the PHP2Shell check and patch guide.

Serve PHP with Apache

Pick Apache or Nginx, not both, since they share port 80. Apache is the shorter path, because the PHP package already drops /etc/httpd/conf.d/php.conf, which hands every .php request to the FPM socket. Install Apache, start both services and drop in a test page.

sudo dnf install -y httpd
sudo systemctl enable --now php-fpm httpd
echo '<?php phpinfo();' | sudo tee /var/www/html/info.php

Apache reads conf.d only when it starts. If httpd was already running before you installed PHP, run sudo systemctl restart httpd, otherwise the handler is not loaded and the browser gets your source code. We reproduced that on web02 by starting Apache without php.conf, and the request returned 200 OK with the literal <?php phpinfo(); in the body. With the handler in place, the Server API line is the one to look for.

Apache serving PHP 8.4.27 through PHP-FPM on Rocky Linux 9 with SELinux enforcing

The same commands gave the same result on the 10 series with the AppStream php8.4 build. SELinux needed no change for this, and ausearch on web02 logged no denials. If you run Apache in front of PHP, keep it patched as well; the mod_http2 patch for Rocky Linux and AlmaLinux is the current one to apply.

Serve PHP with Nginx

Nginx talks to PHP-FPM over its Unix socket. If you tried Apache first, stop it with sudo systemctl disable --now httpd so the port is free, then install Nginx.

sudo dnf install -y nginx

Leave Nginx stopped for now. It starts once the server block is in place and nginx -t passes.

Keep the PHP-FPM pool user as apache

Leave user = apache in /etc/php-fpm.d/www.conf, even on an Nginx server. The packaged session directory /var/lib/php/session belongs to group apache with mode 770, so a pool running as nginx can’t write sessions and every login breaks with session_start(): ... Permission denied (13). Nginx already reaches the socket through the ACL line the package ships.

grep -E '^(user|group|listen|listen.acl_users) ' /etc/php-fpm.d/www.conf

Both releases returned identical defaults, so there is nothing to change here.

user = apache
group = apache
listen = /run/php-fpm/www.sock
listen.acl_users = apache,nginx

The process manager is the part you tune. To size pm.max_children, divide the RAM you can give PHP by about 40 MB per worker; the packaged 50 suits a 4 GB server, while a 2 GB box is safer at 20 to 30. Lower pm.max_spare_servers with it, because the packaged value is 35. When we set 25 children alone, php-fpm refused to start with pm.min_spare_servers(5) and pm.max_spare_servers(35) cannot be greater than pm.max_children(25), and 15 spare servers fixed it. Edit the pool with sudo vim /etc/php-fpm.d/www.conf and test it before any restart.

sudo php-fpm -t

A clean pool prints a single notice:

[13-Nov-2026 09:16:13] NOTICE: configuration file /etc/php-fpm.conf test is successful

Restart php-fpm only after that line appears. A broken pool file stops the service, and every PHP page then returns 502.

Add the server block

Create the site config with sudo vim /etc/nginx/conf.d/default.conf. Keep both listen lines, for the reason given right after the block.

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

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

Our first version had only listen 80; and returned 404 for info.php when curl asked localhost with our site’s Host header. The Nginx error log explained it: localhost resolved to ::1, and the only server on IPv6 port 80 was the stock one in nginx.conf, whose root is /usr/share/nginx/html:

2026/11/13 09:16:21 [error] 7852#7852: *3 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: ::1, server: _, request: "HEAD /info.php HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/www.sock:", host: "php.example.com"

The same request to 127.0.0.1 returned 200 OK, so anything reaching the server over IPv6 would have hit the wrong root. Adding listen [::]:80; fixed it, because our block now loads first on both addresses. On both series, php-fpm also ships /etc/nginx/conf.d/php-fpm.conf (an upstream named php-fpm) and /etc/nginx/default.d/php.conf, which the stock server includes. Leave them, because the block above uses the socket directly and works with or without them. Test and enable Nginx.

sudo nginx -t
sudo systemctl enable --now php-fpm nginx

Later config edits only need sudo systemctl reload nginx. A reload returns before the workers have the new config, so a curl in the same breath can still see the old server. Give it a second before you test.

Tune php.ini and OPcache

The packaged php.ini is conservative. Open it with sudo vim /etc/php.ini and set the values a typical CMS needs.

memory_limit = 256M
max_execution_time = 300
max_input_vars = 5000
upload_max_filesize = 64M
post_max_size = 64M
display_errors = Off
log_errors = On
session.cookie_httponly = 1
session.cookie_secure = 1
session.use_strict_mode = 1
date.timezone = UTC

Leave error_log unset. The pool file sets php_admin_value[error_log] = /var/log/php-fpm/www-error.log, so warnings from web requests already land there. And session.cookie_secure = 1 means browsers only send the session cookie over HTTPS, so logins on a plain HTTP test site will not stick until TLS is in place.

For OPcache, don’t overwrite /etc/php.d/10-opcache.ini: its first line is zend_extension=opcache, and a file pasted over it silently unloads OPcache. A later drop-in overrides the values instead. Create /etc/php.d/99-opcache-tuning.ini with sudo vim and add these lines.

opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=10000
opcache.revalidate_freq=60
opcache.validate_timestamps=1

Restart PHP-FPM with sudo systemctl restart php-fpm, then confirm the drop-in won with php -i | grep -E '^opcache.(memory_consumption|revalidate_freq)'. Ours printed 128 and 60. During active development, set revalidate_freq to 0 so edits show up immediately.

Open the firewall

firewalld runs by default on both families and blocks web traffic until you allow it.

sudo firewall-cmd --permanent --add-service=http --add-service=https
sudo firewall-cmd --reload
sudo firewall-cmd --list-services

The list must include http and https. On a cloud image the zone may hold nothing else, since the provider’s own firewall handles SSH, so don’t worry if ssh is missing from the output.

Configure SELinux for PHP-FPM

Leave SELinux enforcing. Serving pages needs no change at all, so you only add what the application does beyond reading files. A PHP app that talks to MySQL on Rocky Linux, calls external APIs or sends mail needs these booleans.

sudo setsebool -P httpd_can_network_connect_db 1
sudo setsebool -P httpd_can_network_connect 1
sudo setsebool -P httpd_can_sendmail 1
getsebool httpd_can_network_connect_db httpd_can_network_connect httpd_can_sendmail

Each of the three reports on. Writes are the part that breaks apps. Even when the directory belongs to apache, the default httpd_sys_content_t label is read only for php-fpm. We pointed a two-line test script at an apache-owned /var/www/html/data and got bool(false), a Permission denied warning in www-error.log and an AVC denial. Then we relabelled a second directory and the same write went through.

SELinux AVC denial blocks php-fpm writes until semanage and restorecon relabel the directory httpd_sys_rw_content_t

The relabel only needs semanage, which comes from policycoreutils-python-utils. Swap storage for your app’s cache or data path:

sudo dnf install -y policycoreutils-python-utils
sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/storage(/.*)?"
sudo restorecon -Rv /var/www/html/storage

A directory named uploads anywhere under /var/www/html is already writable, because the shipped policy carries the rule /var/www/html(/.*)?/uploads(/.*)?. Check with ls -dZ before adding a rule you do not need, and when a write fails, sudo ausearch -m avc -ts recent names the exact path and label.

Test PHP in the browser

With info.php in the web root from the Apache section, or the same one-line file created now, open http://10.0.1.50/info.php using your server’s address. On our Rocky web01 behind Nginx it showed the Remi build, FPM/FastCGI as the Server API and the OPcache drop-in at the end of the parsed files.

phpinfo page for PHP 8.4.27 on Rocky Linux 10 showing FPM/FastCGI server API and 99-opcache-tuning.ini loaded

Delete the file as soon as you’ve seen it, because it hands scanners your exact PHP build and module list:

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

From here the stack is ready for an application. The WordPress with Nginx guide builds on exactly this PHP-FPM setup, and the DokuWiki guide adds a Let’s Encrypt certificate to the same Nginx layout.

Switch PHP versions later

How you switch depends on the source you installed from. On Remi, one command moves between branches. Resetting the module and running distro-sync takes you back to whatever AppStream offers. On the 10 series dnf prints a modularity deprecation warning here, but it is only a notice and the commands work. We moved web01 up to 8.5, back to 8.4, then out of Remi entirely.

dnf module switch-to moving PHP from remi-8.4 to remi-8.5 and back, then distro-sync to AppStream PHP 8.3.36

On the AppStream php8.4 packages there is no module involved, so going back to 8.3 is the --allowerasing swap in reverse.

sudo dnf install -y --allowerasing php php-cli php-fpm php-mysqlnd php-gd php-mbstring php-xml php-curl php-zip php-opcache php-bcmath php-intl php-soap

After any switch, restart PHP-FPM, run php --version and repeat the rpm -qa 'php*-common' check against the PHP2Shell table, because a branch change can land you on an unpatched build.

Harden PHP before it takes traffic

A working phpinfo page is not a production server yet. Four jobs remain before real users arrive:

  • TLS in front, since the session settings assume HTTPS
  • pm.status_path on a localhost-only location
  • logrotate coverage for /var/log/php-fpm/
  • a routine dnf upgrade 'php*' plus php-fpm restart

Watch the status page before raising pm.max_children, so you size workers from real load. Above all, treat dnf upgrade 'php*' plus a php-fpm restart as a routine job: PHP2Shell showed that a fix can sit on the mirrors for days while the old workers keep serving. On the 10 series we’d stay on AppStream’s php8.4 and let the distro carry it. On the 9 series, Remi’s 8.4 is the only current choice, and its updates landed within a day of upstream in October.

Keep reading

PHP2Shell and CVE-2026-115560 on EOL PHP 8.1, 8.0 and 7.4 Php PHP2Shell and CVE-2026-115560 on EOL PHP 8.1, 8.0 and 7.4 Customize KDE Plasma Desktop with Themes|Modules|Extensions AlmaLinux Customize KDE Plasma Desktop with Themes|Modules|Extensions Linux Terminal Shortcuts Cheat Sheet (Bash and zsh) Cheat Sheets Linux Terminal Shortcuts Cheat Sheet (Bash and zsh) WP Rocket CVE-2026-125812: Check, Patch and Hunt Planted Files Security WP Rocket CVE-2026-125812: Check, Patch and Hunt Planted Files How to Speed Up High-Traffic Websites Using Nginx and Redis Caching Web Hosting How to Speed Up High-Traffic Websites Using Nginx and Redis Caching Install Xen Orchestra on Rocky / CentOS / AlmaLinux AlmaLinux Install Xen Orchestra on Rocky / CentOS / AlmaLinux

Leave a Comment

Press ESC to close