How to Install PHP 8.2 on Rocky Linux EL9 or EL8

PHP 8.2 has been officially released, along with the retirement of PHP 7.4. Rocky Linux does not support this version in either EL9 or EL8 but can be installed using the Remi PHP Repo. In the following tutorial, you will learn how to import the REMI PHP Module and install PHP 8.2 on Rocky Linux, along with some tips about configuring Nginx with FPM using the command line terminal.

Recommended Steps Before Installation

First, update your system to ensure all existing packages are up to date. This will ensure no conflicts arise as best as possible during the installation.

sudo dnf upgrade --refresh

Import PHP Remi Repository

The first task is to install the (EPEL) repository, which stands for (Extra Packages for Enterprise Linux). For newer users of Rocky Linux and similar distributions based on RHEL, EPEL contains the most commonly used software packages for Enterprise Linux.

Import the PHP repository that matches your version of Rocky Linux.

Import REMI PHP Repo for Rocky Linux EL 9

Next, install EPEL using the following (dnf) terminal command.

sudo dnf install \ \

Now that you have added the EPEL repository, enable the (Remi repository) with the following command.

sudo dnf install dnf-utils -y

Import REMI PHP Repo for Rocky Linux EL 8

Similar to EPEL 9 method, install EPEL using the following (dnf) terminal command. This command changes the version numbers.

sudo dnf install \ \

Now that you have added the EPEL repository, enable the (Remi repository) with the following command.

sudo dnf install dnf-utils -y

Next, verify the installation.

dnf repolist | grep remi

Example output:

[joshua@rocky-linux ~]$ dnf repolist | grep remi
remi-modular     Remi's Modular repository for Enterprise Linux 9 - x86_64
remi-safe        Safe Remi's RPM repository for Enterprise Linux 9 - x86_64

Alternatively, you can list all modules on your system with the following command.

dnf module list

Example output:

[joshua@rocky-linux ~]$ sudo dnf module list 
Last metadata expiration check: 0:02:27 ago on Mon 19 Dec 2022 10:03:47.
Rocky Linux 9 - AppStream
Name                               Stream                            Profiles                                                       Summary                                                                        
maven                              3.8                               common [d]                                                     Java project management and project comprehension tool                         
nodejs                             18                                common [d], development, minimal, s2i                          Javascript runtime                                                             
php                                8.1                               common [d], devel, minimal                                     PHP scripting language                                                         
ruby                               3.1                               common [d]                                                     An interpreter of object-oriented scripting language                           

Remi's Modular repository for Enterprise Linux 9 - x86_64
Name                               Stream                            Profiles                                                       Summary                                                                        
composer                           2                                 common [d]                                                     Dependency Manager for PHP                                                     
memcached                          remi                              common [d]                                                     High Performance, Distributed Memory Object Cache                              
php                                remi-7.4                          common [d], devel, minimal                                     PHP scripting language                                                         
php                                remi-8.0                          common [d], devel, minimal                                     PHP scripting language                                                         
php                                remi-8.1                          common [d], devel, minimal                                     PHP scripting language                                                         
php                                remi-8.2                          common [d], devel, minimal                                     PHP scripting language                                                         
redis                              remi-5.0                          common [d]                                                     Redis persistent key-value database                                            
redis                              remi-6.0                          common [d]                                                     Redis persistent key-value database                                            
redis                              remi-6.2                          common [d]                                                     Redis persistent key-value database                                            
redis                              remi-7.0                          common [d]                                                     Redis persistent key-value database                                            

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

As mentioned above, you have imported the Remi repository with PHP 8.2 available along with other modules such as Redis, Memcached, and PHP Composer if you wish to install an alternative newer version in most cases to that of what Rocky Linux contains.

See also
How to Install CMake on Rocky Linux EL9 or EL8

Situational – Remove Existing PHP Install

For users that have already installed PHP, you can import the Remi repository or change the branch within it, for example going from 8.1 to 8.2. Still, it may be beneficial to back up your existing configurations and remove PHP.

This is not required, you can directly upgrade, and it should work mostly. Just be aware the configurations will most likely change, so if you do not remove the existing PHP version, ensure you back up any custom configurations such as the “php.ini.”

Make sure to back up any configuration files.

sudo dnf remove php php-fpm -y

Then remove the rest of the package extensions.

sudo dnf remove php* -y

To reset the PHP module list is easy with the following command:

sudo dnf module list reset php -y

Now you can proceed to the next part of the tutorial.

Enable PHP 8.2 (Remi) Repository

A quick tip is to use the dnf module list command to see the options available and the default.

The following dnf module list command can do this:

sudo dnf module list php

Example output:

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

Remi's Modular repository for Enterprise Linux 9 - x86_64
Name                                      Stream                                        Profiles                                                        Summary                                                    
php                                       remi-7.4                                      common [d], devel, minimal                                      PHP scripting language                                     
php                                       remi-8.0                                      common [d], devel, minimal                                      PHP scripting language                                     
php                                       remi-8.1                                      common [d], devel, minimal                                      PHP scripting language                                     
php                                       remi-8.2                                      common [d], devel, minimal                                      PHP scripting language                                     

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

You will be prompted to import the GPG key for Remi’s repository. Type (Y) to proceed if you encounter it.

Next, enable PHP 8.2 with the following command.

sudo dnf module enable php:remi-8.2 -y

Example output:

 Package                Architecture          Version                Repository              Size
Enabling module streams:
 php                                          remi-8.2                                           

Transaction Summary

Install PHP 8.2 Apache or Nginx Support

Now that you have added the Remi PHP repository and enabled PHP 8.2 to be the default version on your system, you can install PHP with the following command.

Apache (httpd) Users:

sudo dnf install php -y

Nginx Users:

sudo dnf install php php-fpm -y

Optionally, if you would like to install the most commonly used extensions for PHP 8.2, use the following command:

sudo dnf install php-cli php-fpm php-curl php-mysqlnd php-gd php-opcache php-zip php-intl php-common php-bcmath php-imagick php-xmlrpc php-json php-readline php-memcached php-redis php-mbstring php-apcu php-xml php-dom php-redis php-memcached php-memcache

Note, remove the options you do not want. This is optional, and it is recommended only to install and keep what modules you require from a performance and security standard.

See also
How to Install Neofetch on Rocky Linux EL9 or EL8

Alternatively, you can search for your desired PHP extension with the following command.

sudo dnf search php82-php-

Example output:

[joshua@rocky-linux ~]$ sudo dnf search php82-php-

Last metadata expiration check: 0:04:49 ago on Mon 19 Dec 2022 10:03:47.

======================================================================Name & Summary Matched: php82-php- ======================================================================

php82-php-pecl-pcsc-devel.x86_64 : php82-php-pecl-pcsc developer files (header)
php82-php-pecl-psr-devel.x86_64 : php82-php-pecl-psr developer files (header)
php82-php-pecl-raphf-devel.x86_64 : php82-php-pecl-raphf developer files (header)
php82-php-pecl-xmldiff-devel.x86_64 : php82-php-pecl-xmldiff developer files (header)
php82-php-pecl-yaconf-devel.x86_64 : php82-php-pecl-yaconf developer files (header)
php82-php-zephir-parser-devel.x86_64 : php82-php-zephir-parser developer files (headers)
php82-php-zstd-devel.x86_64 : php82-php-zstd developer files (header)

======================================================================Name Matched: php82-php- ======================================================================
php82-php-ast.x86_64 : Abstract Syntax Tree
php82-php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
php82-php-brotli.x86_64 : Brotli Extension for PHP
php82-php-cli.x86_64 : Command-line interface for PHP
php82-php-common.x86_64 : Common files for PHP
php82-php-dba.x86_64 : A database abstraction layer module for PHP applications
php82-php-dbg.x86_64 : The interactive PHP debugger
php82-php-devel.x86_64 : Files needed for building PHP extensions
php82-php-embedded.x86_64 : PHP library for embedding in applications
php82-php-enchant.x86_64 : Enchant spelling extension for PHP applications
php82-php-ffi.x86_64 : Foreign Function Interface
php82-php-fpm.x86_64 : PHP FastCGI Process Manager
php82-php-gd.x86_64 : A module for PHP applications for using the gd graphics library
php82-php-geos.x86_64 : PHP module for GEOS
php82-php-gmp.x86_64 : A module for PHP applications for using the GNU MP library
php82-php-imap.x86_64 : A module for PHP applications that use IMAP
php82-php-intl.x86_64 : Internationalization extension for PHP applications
php82-php-ldap.x86_64 : A module for PHP applications that use LDAP
php82-php-libvirt.x86_64 : PHP language binding for Libvirt
php82-php-libvirt-doc.noarch : Document of php-libvirt
php82-php-litespeed.x86_64 : LiteSpeed Web Server PHP support
php82-php-lz4.x86_64 : LZ4 Extension for PHP
php82-php-maxminddb.x86_64 : MaxMind DB Reader extension
php82-php-mbstring.x86_64 : A module for PHP applications which need multi-byte string handling
php82-php-mysqlnd.x86_64 : A module for PHP applications that use MySQL databases
php82-php-oci8.x86_64 : A module for PHP applications that use OCI8 databases
php82-php-odbc.x86_64 : A module for PHP applications that use ODBC databases
php82-php-opcache.x86_64 : The Zend OPcache
php82-php-pdo.x86_64 : A database access abstraction module for PHP applications
php82-php-pdo-dblib.x86_64 : PDO driver for Microsoft SQL Server and Sybase databases
php82-php-pdo-firebird.x86_64 : PDO driver for Interbase/Firebird databases
php82-php-pear.noarch : PHP Extension and Application Repository framework
php82-php-pecl-ahocorasick.x86_64 : Effective Aho-Corasick string pattern matching algorithm
php82-php-pecl-amqp.x86_64 : Communicate with any AMQP compliant server
php82-php-pecl-apcu.x86_64 : APC User Cache
php82-php-pecl-apcu-devel.x86_64 : APCu developer files (header)
php82-php-pecl-apfd.x86_64 : Always Populate Form Data
php82-php-pecl-awscrt.x86_64 : AWS Common Runtime PHP bindings
php82-php-pecl-base58.x86_64 : Encode and decode data with base58
php82-php-pecl-bitset.x86_64 : BITSET library
php82-php-pecl-bsdiff.x86_64 : The bsdiff extension for PHP
php82-php-pecl-cassandra.x86_64 : DataStax PHP Driver for Apache Cassandra
php82-php-pecl-couchbase3.x86_64 : Couchbase Server PHP extension
php82-php-pecl-couchbase4.x86_64 : Couchbase Server PHP extension
php82-php-pecl-crypto.x86_64 : Wrapper for OpenSSL Crypto Library
php82-php-pecl-csv.x86_64 : CSV PHP extension
php82-php-pecl-datadog-trace.x86_64 : APM and distributed tracing for PHP
php82-php-pecl-dbase.x86_64 : dBase database file access functions
php82-php-pecl-decimal.x86_64 : Arbitrary-precision floating-point decimal
php82-php-pecl-dio.x86_64 : Direct I/O functions
php82-php-pecl-ds.x86_64 : Data Structures for PHP
php82-php-pecl-eio.x86_64 : Provides interface to the libeio library
php82-php-pecl-env.x86_64 : Load environment variables
php82-php-pecl-ev.x86_64 : Provides interface to libev library
php82-php-pecl-event.x86_64 : Provides interface to libevent library
php82-php-pecl-excimer.x86_64 : Interrupting timer and low-overhead sampling profiler
php82-php-pecl-fann.x86_64 : Wrapper for FANN Library
php82-php-pecl-gearman.x86_64 : PHP wrapper to libgearman
php82-php-pecl-geoip.x86_64 : Extension to map IP addresses to geographic places
php82-php-pecl-geospatial.x86_64 : PHP Extension to handle common geospatial functions
php82-php-pecl-gmagick.x86_64 : Provides a wrapper to the GraphicsMagick library
php82-php-pecl-gnupg.x86_64 : Wrapper around the gpgme library
php82-php-pecl-grpc.x86_64 : General RPC framework
php82-php-pecl-handlebars.x86_64 : Handlebars templating language
php82-php-pecl-hdr-histogram.x86_64 : PHP extension wrapper for the C hdrhistogram API
php82-php-pecl-http.x86_64 : Extended HTTP support
php82-php-pecl-http-devel.x86_64 : Extended HTTP support developer files (header)
php82-php-pecl-igbinary.x86_64 : Replacement for the standard PHP serializer
php82-php-pecl-igbinary-devel.x86_64 : Igbinary developer files (header)
php82-php-pecl-imagick-im6.x86_64 : Extension to create and modify images using ImageMagick 6
php82-php-pecl-imagick-im6-devel.x86_64 : imagick extension developer files (header)
php82-php-pecl-imagick-im7.x86_64 : Extension to create and modify images using ImageMagick 7
php82-php-pecl-imagick-im7-devel.x86_64 : imagick extension developer files (header)
php82-php-pecl-immutable-cache.x86_64 : An shared memory cache of immutable values
php82-php-pecl-inotify.x86_64 : Inotify
php82-php-pecl-ion.x86_64 : Amazon ION support
php82-php-pecl-ip2location.x86_64 : Get geo location information of an IP address
php82-php-pecl-ip2proxy.x86_64 : Get proxy information of an IP address
php82-php-pecl-json-post.x86_64 : JSON POST handler
php82-php-pecl-jsonpath.x86_64 : Extract data using JSONPath notation
php82-php-pecl-krb5.x86_64 : Kerberos authentification extension
php82-php-pecl-krb5-devel.x86_64 : Kerberos extension developer files (header)
php82-php-pecl-leveldb.x86_64 : LevelDB PHP bindings
php82-php-pecl-luasandbox.x86_64 : Lua interpreter with limits and safe environment
php82-php-pecl-lzf.x86_64 : Extension to handle LZF de/compression
php82-php-pecl-mailparse.x86_64 : PHP PECL package for parsing and working with email messages
php82-php-pecl-mcrypt.x86_64 : Bindings for the libmcrypt library
php82-php-pecl-memcache.x86_64 : Extension to work with the Memcached caching daemon
php82-php-pecl-memcached.x86_64 : Extension to work with the Memcached caching daemon
php82-php-pecl-memprof.x86_64 : Memory usage profiler
php82-php-pecl-mongodb.x86_64 : MongoDB driver for PHP
php82-php-pecl-msgpack.x86_64 : API for communicating with MessagePack serialization
php82-php-pecl-msgpack-devel.x86_64 : MessagePack developer files (header)
php82-php-pecl-mustache.x86_64 : Mustache templating language
php82-php-pecl-mysql.x86_64 : MySQL database access functions
php82-php-pecl-mysql-xdevapi.x86_64 : MySQL database access functions
php82-php-pecl-nsq.x86_64 : PHP extension for NSQ client
php82-php-pecl-oauth.x86_64 : PHP OAuth consumer extension
php82-php-pecl-opencensus.x86_64 : A stats collection and distributed tracing framework
php82-php-pecl-openswoole.x86_64 : PHP's asynchronous concurrent distributed networking framework
php82-php-pecl-pam.x86_64 : PAM integration
php82-php-pecl-parle.x86_64 : Parsing and lexing
php82-php-pecl-pcov.x86_64 : Code coverage driver
php82-php-pecl-pcsc.x86_64 : An extension for PHP using the winscard PC/SC API
php82-php-pecl-pkcs11.x86_64 : PHP Bindings for PKCS11 modules
php82-php-pecl-pq.x86_64 : PostgreSQL client library (libpq) binding
php82-php-pecl-protobuf.x86_64 : Mechanism for serializing structured data
php82-php-pecl-ps.x86_64 : An extension to create PostScript files
php82-php-pecl-psr.x86_64 : PSR interfaces
php82-php-pecl-quickhash.x86_64 : Set of specific strongly-typed classes for sets and hashing
php82-php-pecl-raphf.x86_64 : Resource and persistent handles factory
php82-php-pecl-rdkafka6.x86_64 : Kafka client based on librdkafka
php82-php-pecl-recode.x86_64 : A module for PHP applications for using the recode library
php82-php-pecl-redis5.x86_64 : Extension for communicating with the Redis key-value store
php82-php-pecl-rnp.x86_64 : wrapper around the RNP library
php82-php-pecl-rpminfo.x86_64 : RPM information
php82-php-pecl-rrd.x86_64 : PHP Bindings for rrdtool
php82-php-pecl-runkit7.x86_64 : For all those things you... shouldn't have been doing anyway... but surely do!
php82-php-pecl-scoutapm.x86_64 : Native Extension Component for ScoutAPM's PHP Agent
php82-php-pecl-scrypt.x86_64 : Scrypt hashing function
php82-php-pecl-sdl.x86_64 : Simple DirectMedia Layer for PHP
php82-php-pecl-sdl-image.x86_64 : SDL_image bindings for PHP
php82-php-pecl-sdl-mixer.x86_64 : Binding of SDL_mixer for PHP
php82-php-pecl-sdl-ttf.x86_64 : SDL_ttf bindings for PHP
php82-php-pecl-seaslog.x86_64 : An effective, fast, stable log extension for PHP
php82-php-pecl-seassnowflake.x86_64 : PHP Extension for Distributed unique ID generator
php82-php-pecl-selinux.x86_64 : SELinux binding for PHP scripting language
php82-php-pecl-simdjson.x86_64 : Provides faster json decoding through simdjson bindings for PHP
php82-php-pecl-simple-kafka-client.x86_64 : Kafka client based on librdkafka
php82-php-pecl-skywalking.x86_64 : The PHP instrument agent for Apache SkyWalking
php82-php-pecl-solr2.x86_64 : API orientée objet pour Apache Solr
php82-php-pecl-ssdeep.x86_64 : Wrapper for libfuzzy library
php82-php-pecl-ssh2.x86_64 : Bindings for the libssh2 library
php82-php-pecl-stats.x86_64 : Routines for statistical computation
php82-php-pecl-stomp.x86_64 : Stomp client extension
php82-php-pecl-swoole4.x86_64 : PHP's asynchronous concurrent distributed networking framework
php82-php-pecl-swoole5.x86_64 : PHP's asynchronous concurrent distributed networking framework
php82-php-pecl-sync.x86_64 : Named and unnamed synchronization objects
php82-php-pecl-teds.x86_64 : Tentative Extra Data Structures
php82-php-pecl-trader.x86_64 : Technical Analysis for traders
php82-php-pecl-translit.x86_64 : Transliterates non-latin character sets to latin
php82-php-pecl-trie.x86_64 : PHP Trie extension
php82-php-pecl-uopz.x86_64 : User Operations for Zend
php82-php-pecl-uploadprogress.x86_64 : An extension to track progress of a file upload
php82-php-pecl-uuid.x86_64 : Universally Unique Identifier extension for PHP
php82-php-pecl-var-representation.x86_64 : A compact, more readable alternative to var_export
php82-php-pecl-varnish.x86_64 : Varnish Cache bindings
php82-php-pecl-vips.x86_64 : PHP extension for interfacing with libvips
php82-php-pecl-vld.x86_64 : Dump the internal representation of PHP scripts
php82-php-pecl-xattr.x86_64 : Extended attributes
php82-php-pecl-xdebug3.x86_64 : Provides functions for function traces and profiling
php82-php-pecl-xdiff.x86_64 : File differences/patches
php82-php-pecl-xhprof.x86_64 : PHP extension for XHProf, a Hierarchical Profiler
php82-php-pecl-xlswriter.x86_64 : An efficient and fast xlsx file extension
php82-php-pecl-xmldiff.x86_64 : XML diff and merge
php82-php-pecl-xmlrpc.x86_64 : Functions to write XML-RPC servers and clients
php82-php-pecl-xxtea.x86_64 : XXTEA encryption algorithm extension for PHP
php82-php-pecl-yac.x86_64 : Lockless user data cache
php82-php-pecl-yaconf.x86_64 : Yet Another Configurations Container
php82-php-pecl-yaf.x86_64 : Yet Another Framework
php82-php-pecl-yaml.x86_64 : PHP Bindings for yaml
php82-php-pecl-yar.x86_64 : Light, concurrent RPC framework
php82-php-pecl-yaz.x86_64 : Z39.50/SRU client
php82-php-pecl-zip.x86_64 : A ZIP archive management extension
php82-php-pecl-zmq.x86_64 : ZeroMQ messaging
php82-php-pgsql.x86_64 : A PostgreSQL database module for PHP
php82-php-phpiredis.x86_64 : Client extension for Redis
php82-php-process.x86_64 : Modules for PHP script using system process interfaces
php82-php-pspell.x86_64 : A module for PHP applications for using pspell interfaces
php82-php-realpath-turbo.x86_64 : Use realpath cache despite open_basedir restriction
php82-php-smbclient.x86_64 : PHP wrapper for libsmbclient
php82-php-snappy.x86_64 : Snappy Extension for PHP
php82-php-snmp.x86_64 : A module for PHP applications that query SNMP-managed devices
php82-php-soap.x86_64 : A module for PHP applications that use the SOAP protocol
php82-php-sodium.x86_64 : Wrapper for the Sodium cryptographic library
php82-php-sqlsrv.x86_64 : Microsoft Drivers for PHP for SQL Server
php82-php-tidy.x86_64 : Standard PHP module provides tidy library support
php82-php-xml.x86_64 : A module for PHP applications which use XML
php82-php-xz.x86_64 : XZ (LZMA2) compression/decompression
php82-php-zephir-parser.x86_64 : Zephir code parser
php82-php-zstd.x86_64 : Zstandard extension

A handy hint is that you do not need to use php82-PHP when installing packages. This helps filter down the PHP 8.2 packages, or else you will get all the previous versions listed, which makes it a bit more confusing.

See also
How to Increase DNF Speed on Rocky Linux EL9 or EL8

You can use the following command to view modules loaded at any time.

php -m

Example output (They will 100% vary):

[PHP Modules]
Zend OPcache

[Zend Modules]
Zend OPcache

Depending on how many modules you have installed, this can be pretty large, and it is always recommended to keep an eye on this and remove any you do not need.

Lastly, use the following command for anyone interested in installing the development branch.

sudo dnf install php-devel

Additional developments tool, such as debugging tools, use the following command.

sudo dnf install php-xdebug php-pcov

This will install many dependencies, and unless you are developing with PHP or have some special requirement to install it, do not use this version.

Now that you have installed PHP 8.2 and the extensions, check the version with the following command:

php -v

Example output:

[joshua@rocky-linux ~]$ php -v
PHP 8.2.0 (cli) (built: Dec  6 2022 14:26:47) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.2.0, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.0, Copyright (c), by Zend Technologies
    with Xdebug v3.2.0, Copyright (c) 2002-2022, by Derick Rethans

PHP-FPM Installations of PHP 8.2

Unlike PHP-FPM installations on Debian/Ubuntu that use the (www-data) user, this isn’t the case with RHEL family installations. By default, the PHP-FPM service is designed to be run by (Apache) user, which is incorrect since we are using Nginx, which needs to be corrected.

Firstly, open the following (www.conf) configuration file:

sudo nano /etc/php-fpm.d/www.conf

Next, replace the (Apache) user and group with the (Nginx) user and group.

Example with username originally Apache:

Example with username change to Nginx:

To save, press (CTRL+O) for the nano editor, then exit (CTRL+X).

Now you will, too, reload or restart your PHP-FPM service.

sudo systemctl restart php-fpm

Nginx Configurement

The Nginx server block needs the following example below for Nginx to process the PHP files.

Below is an example for all server {} blocks that process PHP files that need the location ~ .php$ added.

Example ONLY:

    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 Nginx to make sure you have no errors with the adjustments made with the code above; enter the following.

sudo nginx -t

Example output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Restart the Nginx service for installation to be complete.

sudo systemctl restart nginx


This tutorial demonstrates installing PHP 8.2 on Rocky Linux using the command line terminal and the Remi RPM Repo so you can install the latest PHP version on your server for your CMS or development.

Leave a Comment

Share to...