How to Install PHP on Rocky Linux 10, 9 and 8

Install PHP on Rocky Linux 10, 9 and 8 using default AppStream repos. Covers Apache, Nginx PHP-FPM, extensions, and version switching.

Last updatedAuthorJoshua JamesRead time6 minGuide typeRocky LinuxDiscussion2 comments

PHP on Rocky Linux works best when you match the runtime branch to the release before installing web-server packages or extensions. To install PHP on Rocky Linux, use AppStream for the packaged branch your system already trusts, then add PHP-FPM, CLI tools, and only the extension packages your application actually needs.

Rocky Linux 10 provides PHP 8.3 directly from AppStream. Rocky Linux 9 installs PHP 8.0 by default, but also offers PHP 8.1, 8.2, and 8.3 module streams. Rocky Linux 8 defaults to PHP 7.2 and offers newer module streams up to PHP 8.2. If your application needs PHP 8.4, PHP 8.5, or a Remi module command such as sudo dnf module enable php:remi-8.1, keep that workflow separate from the default AppStream path.

Install PHP on Rocky Linux

AppStream is the default starting point for a standard Rocky Linux server because it keeps PHP updates under Rocky’s normal DNF transaction model. Choose the branch first, then install packages from that branch.

Choose an AppStream PHP Branch

Rocky Linux ReleaseDefault AppStream PHPOptional AppStream StreamsGood AppStream Choice
Rocky Linux 10PHP 8.3 packagesNo PHP module stream in AppStreamInstall PHP 8.3 directly
Rocky Linux 9PHP 8.0 packagesPHP 8.1, 8.2, 8.3Enable php:8.3 for new deployments
Rocky Linux 8PHP 7.2 streamPHP 7.3, 7.4, 8.0, 8.2Enable php:8.2 when the application supports it

For new applications, avoid older streams unless a vendor or legacy codebase requires them. Check the upstream PHP supported versions page before choosing an older branch for internet-facing services.

Use Remi for PHP 8.4 or PHP 8.5 on Rocky Linux

Rocky Linux AppStream does not provide PHP 8.4 or PHP 8.5 for the releases covered here. Those newer branches require a separate repository workflow, and Remi module streams use names such as php:remi-8.5 instead of the default AppStream style such as php:8.3. A command like sudo dnf module enable php:remi-8.1 belongs after Remi is installed and Remi streams are visible, so keep repository setup, stream selection, package installation, and cleanup in the Remi RPM guide for Rocky Linux.

Update Rocky Linux Packages

Refresh DNF metadata and apply pending updates before changing PHP packages:

sudo dnf upgrade --refresh

Commands that use sudo prompt for your account password. DNF also shows a transaction summary before it installs, upgrades, or removes packages, so review the package list before confirming.

Install PHP 8.3 on Rocky Linux 10

Rocky Linux 10 does not use a PHP module stream for the default AppStream branch. Install the PHP command-line binary and PHP-FPM service directly:

sudo dnf install php-cli php-fpm

This package set provides the php command, the php-fpm service, and packaged PHP-FPM integration snippets for Apache and Nginx.

Install PHP 8.3 on Rocky Linux 9

Rocky Linux 9 can install PHP 8.0 without enabling a module stream, but the AppStream module list offers newer branches. Check the available streams first:

dnf module list php
Rocky Linux 9 - AppStream
Name Stream Profiles                   Summary
php  8.1    common [d], devel, minimal PHP scripting language
php  8.2    common [d], devel, minimal PHP scripting language
php  8.3    common [d], devel, minimal PHP scripting language

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

Enable PHP 8.3 for a current AppStream branch on Rocky Linux 9:

sudo dnf module enable php:8.3

After the stream is enabled, install PHP-FPM and the CLI package:

sudo dnf install php-cli php-fpm

Install PHP 8.2 on Rocky Linux 8

Rocky Linux 8 still defaults to PHP 7.2, so enable a newer AppStream stream before installing packages when your application supports it:

dnf module list php
Rocky Linux 8 - AppStream
Name Stream  Profiles                   Summary
php  7.2 [d] common [d], devel, minimal PHP scripting language
php  7.3     common [d], devel, minimal PHP scripting language
php  7.4     common [d], devel, minimal PHP scripting language
php  8.0     common [d], devel, minimal PHP scripting language
php  8.2     common [d], devel, minimal PHP scripting language

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

Enable PHP 8.2 on Rocky Linux 8:

sudo dnf module enable php:8.2

Install the PHP-FPM service and CLI package from the enabled stream:

sudo dnf install php-cli php-fpm

Verify the PHP Runtime

Print the installed major and minor PHP version:

php -r 'echo "PHP " . PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION . PHP_EOL;'

Rocky Linux 10 and Rocky Linux 9 with the php:8.3 stream return:

PHP 8.3

Rocky Linux 8 with the php:8.2 stream returns:

PHP 8.2

Configure PHP-FPM on Rocky Linux

PHP-FPM runs PHP as a separate service. Apache and Nginx can hand PHP requests to this service through the packaged socket at /run/php-fpm/www.sock.

Start and Enable PHP-FPM

Enable PHP-FPM at boot and start it now:

sudo systemctl enable --now php-fpm

Check that the service is active and enabled:

systemctl is-active php-fpm
systemctl is-enabled php-fpm
active
enabled

Check the Default PHP-FPM Socket

The default Rocky Linux pool keeps the service account set to apache, while granting socket ACL access to both apache and nginx. Confirm the pool settings before changing them:

grep -E '^(user|group|listen|listen\.acl_users) =' /etc/php-fpm.d/www.conf
user = apache
group = apache
listen = /run/php-fpm/www.sock
listen.acl_users = apache,nginx

Do not change the pool user to nginx just to make the default socket work. The packaged ACL line already allows Nginx to connect to PHP-FPM when Nginx is installed and running under the standard nginx user.

Connect Nginx to PHP-FPM

The PHP-FPM package installs Nginx snippets, but many virtual hosts still use an explicit PHP location block. The socket path should match the default pool:

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

Test the Nginx configuration and reload the service after editing a server block:

sudo nginx -t
sudo systemctl reload nginx

For a full Nginx package, service, and firewall setup, follow the Install Nginx Mainline on Rocky Linux article before wiring an application to PHP-FPM.

Use PHP-FPM with Apache on Rocky Linux

On Apache hosts, the php-fpm package provides the packaged HTTPD integration file at /etc/httpd/conf.d/php.conf. Restart Apache after installing or changing PHP-FPM packages:

sudo systemctl restart php-fpm httpd

Install PHP Extensions on Rocky Linux

Install extension packages from the same AppStream branch as the core PHP runtime. On Rocky Linux 9 and 8, enable the intended PHP stream before installing extensions so DNF resolves matching packages.

Install Common PHP Extensions

Most CMS and framework deployments need database, XML, image, internationalization, cache, and archive support. Install the common AppStream extension set:

sudo dnf install php-gd php-intl php-bcmath php-soap php-ldap php-mysqlnd php-pgsql php-pecl-apcu php-pecl-zip php-mbstring php-pdo php-xml php-opcache
  • php-mysqlnd, php-pdo, and php-pgsql add database drivers for MySQL, MariaDB, PostgreSQL, and PDO-based applications.
  • php-gd, php-xml, php-mbstring, and php-intl support media handling, XML parsing, multibyte strings, and localization.
  • php-pecl-apcu, php-opcache, and php-pecl-zip cover local user cache, opcode cache, and ZIP archive support.
  • php-bcmath, php-soap, and php-ldap support payment, SOAP API, and directory-integration workloads.

Restart PHP-FPM after installing extensions so web requests load the new modules:

sudo systemctl restart php-fpm

Check that the expected modules are available:

php -m | grep -E '^(apcu|bcmath|gd|intl|ldap|mbstring|mysqli|mysqlnd|PDO|pdo_mysql|pdo_pgsql|pgsql|soap|xml|Zend OPcache|zip)$' | LC_ALL=C sort -u
PDO
Zend OPcache
apcu
bcmath
gd
intl
ldap
mbstring
mysqli
mysqlnd
pdo_mysql
pdo_pgsql
pgsql
soap
xml
zip

Add Development and Redis Extensions

Install development headers only on systems that build PECL extensions or compile application dependencies locally:

sudo dnf install php-devel

Rocky Linux 10 AppStream includes both php-pecl-xdebug3 and php-pecl-redis6. Rocky Linux 9 and Rocky Linux 8 AppStream include php-pecl-xdebug3 for their current PHP module streams, while Rocky Linux 9 and 8 AppStream do not provide php-pecl-redis6. Remi PHP streams also use php-pecl-redis6 for the Redis extension, not php-redis. Check the available packages before adding optional PECL modules:

dnf list --available 'php-pecl-*'

If you also need the Redis server for sessions, object caching, or queues, install and manage that service separately with the Install Redis on Rocky Linux guide. The Redis server package and the PHP Redis extension are separate pieces.

Update or Switch PHP Versions on Rocky Linux

Normal package updates stay inside the selected AppStream branch:

sudo dnf upgrade --refresh 'php*'

Switching module streams on Rocky Linux 9 or 8 is a version migration, not a routine update. Reset the current stream, enable the target stream, and synchronize installed PHP packages:

sudo dnf module reset php
sudo dnf module enable php:8.3
sudo dnf distro-sync 'php*'

Use php:8.2 instead of php:8.3 on Rocky Linux 8, where PHP 8.3 is not part of the default AppStream module set.

Troubleshoot PHP on Rocky Linux

DNF Installs the Wrong PHP Version

On Rocky Linux 9 and 8, check which PHP module stream is enabled:

dnf module list php --enabled

If the wrong stream is enabled, reset it and enable the intended branch before synchronizing installed packages:

sudo dnf module reset php
sudo dnf module enable php:8.3
sudo dnf distro-sync 'php*'

Rocky Linux 10 does not use an AppStream PHP module stream, so this fix only applies to Rocky Linux 9 and 8.

PHP-FPM Does Not Serve Nginx Requests

Confirm that PHP-FPM is active and that the default socket exists:

systemctl is-active php-fpm
test -S /run/php-fpm/www.sock && echo "PHP-FPM socket exists"
active
PHP-FPM socket exists

If Nginx still cannot pass PHP requests, recheck the pool ACL line and the Nginx user:

grep '^listen.acl_users' /etc/php-fpm.d/www.conf
id nginx

The default pool should include listen.acl_users = apache,nginx. If the nginx user does not exist, install and configure Nginx before debugging PHP-FPM permissions.

A PHP Extension Package Is Missing

Search the enabled repositories for the extension package name:

dnf list --available 'php-*extension-name*'

Replace extension-name with part of the module name, such as redis, xdebug, or imagick. If AppStream does not provide the package for your Rocky Linux release and PHP branch, use a supported repository workflow such as Remi instead of mixing random RPMs into the system PHP stack.

Remove PHP from Rocky Linux

Stop PHP-FPM before removing the runtime:

sudo systemctl disable --now php-fpm

The quoted 'php*' pattern removes installed PHP packages and PHP extension packages. Review the DNF transaction carefully if the server hosts more than one application.

sudo dnf remove 'php*'

On Rocky Linux 9 or 8, reset the PHP module stream after removing the packages:

sudo dnf module reset php

Remove orphaned dependencies only after reviewing the transaction list:

sudo dnf autoremove

Confirm that the main PHP packages and command are gone:

rpm -q php php-cli php-fpm || true
hash -r
command -v php || echo "php command not found"
package php is not installed
package php-cli is not installed
package php-fpm is not installed
php command not found

This removal path does not delete Apache, Nginx, application files, databases, or third-party repository definitions. If you installed PHP from Remi, use the Remi repository cleanup steps from that workflow.

Conclusion

Rocky Linux can run PHP cleanly from AppStream when the branch matches the release: PHP 8.3 on Rocky Linux 10, PHP 8.3 through a module stream on Rocky Linux 9, and PHP 8.2 through a module stream on Rocky Linux 8. Keep PHP-FPM as the web-server handoff point, install extensions from the same branch, and move to the Remi workflow only when the default repositories do not provide the PHP branch or PECL package your application needs.

Share this guide

Help another Linux user troubleshoot faster

Share this guide with someone troubleshooting Linux systems or saving it for later.

Follow LinuxCapable

Want more LinuxCapable guides in Google?

Add LinuxCapable as a preferred source so Google can show more of our fresh Linux tutorials in Top Stories and From your sources when relevant.

Add LinuxCapable as a preferred source on Google
Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffeeBuy me a coffee

2 thoughts on “How to Install PHP on Rocky Linux 10, 9 and 8”

  1. Im getting the following errors on rockyos 9.5

    Error:
    Problem 1: package php-pecl-memcached-3.3.0-1.el9.x86_64 from epel requires php(api) = 20200930-64, but none of the providers can be installed
    – package php-pecl-memcached-3.3.0-1.el9.x86_64 from epel requires php(zend-abi) = 20200930-64, but none of the providers can be installed
    – conflicting requests
    – package php-common-8.0.30-10.el9.remi.x86_64 from remi-modular is filtered out by modular filtering
    – package php-common-8.0.30-11.el9.remi.x86_64 from remi-modular is filtered out by modular filtering
    – package php-common-8.0.30-1.el9_2.x86_64 from appstream is filtered out by modular filtering
    Problem 2: package php-pecl-memcache-8.2-1.el9.x86_64 from epel requires php(api) = 20200930-64, but none of the providers can be installed
    – package php-pecl-memcache-8.2-1.el9.x86_64 from epel requires php(zend-abi) = 20200930-64, but none of the providers can be installed
    – conflicting requests
    – package php-common-8.0.30-10.el9.remi.x86_64 from remi-modular is filtered out by modular filtering
    – package php-common-8.0.30-11.el9.remi.x86_64 from remi-modular is filtered out by modular filtering
    – package php-common-8.0.30-1.el9_2.x86_64 from appstream is filtered out by modular filtering
    (try to add ‘–skip-broken’ to skip uninstallable packages or ‘–nobest’ to use not only best candidate packages)

    Reply
    • Hi Allen,

      Thank you for reporting the issue! The errors you’re encountering typically occur due to conflicts in PHP version dependencies or filtering in the enabled repositories. Here’s how you can resolve this:

      1. Check Your PHP Module and Repositories:
        First, ensure that the desired PHP version is enabled. Run:
        dnf module list php

        If the required version is not enabled, enable it. For example, for PHP 8.1:

        sudo dnf module enable php:remi-8.1 -y
      2. Disable Modular Filtering:
        The error suggests modular filtering is blocking some packages. You can temporarily disable this by appending the --setopt=modularity_filter=false option:
        sudo dnf install php-pecl-memcached --setopt=modularity_filter=false
      3. Use the ‘–nobest’ Option:
        This allows DNF to consider packages that are not the best candidate but can resolve the dependency issue:
        sudo dnf install php-pecl-memcached --nobest
      4. Ensure Dependencies Are Installed:
        Some missing dependencies might need to be installed manually. Run:
        sudo dnf install php-common php-zend-abi php-api

        Replace these with the exact dependencies as indicated in the error messages.

      5. Skip Broken Packages:
        To bypass any unresolvable packages, you can add the --skip-broken flag:
        sudo dnf install php-pecl-memcached --skip-broken

      These steps should help resolve the conflict. If you still face issues, let me know the exact output, and I’ll assist you further!

      Reply
Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed in published comments:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<blockquote>quote</blockquote> quote block

Got a Question or Feedback?

We read and reply to every comment - let us know how we can help or improve this guide.

Verify before posting: