How to Install PHP 8.2, 8.1, 8.0, 7.4 on Fedora Linux

PHP, or Hypertext Preprocessor, is a popular open-source programming language perfect for web development. Integrating it into your Fedora Linux system is a breeze and offers many perks. Some of the standout benefits of using PHP include the following:

  • Perform server-side scripting, allowing for dynamic web pages and improved security.
  • Be compatible across different operating systems, including Windows, Mac, and Linux, making it a versatile choice for web development.
  • Have a large and active community of developers, providing a wealth of resources and support.
  • Offer a wide range of built-in functions that can perform common web development tasks, such as connecting databases, sending emails, and creating image thumbnails.
  • Support popular databases, including MySQL, PostgreSQL, and Oracle, making it easy to work with databases in PHP projects.
  • Be integrated with other technologies, such as JavaScript and AJAX, to create interactive and dynamic web applications.
  • An extensive collection of libraries and frameworks, like Laravel, CodeIgniter, and Zend Framework, can be used to simplify and speed up web development.
  • Be relatively easy to learn, making it an excellent choice for beginners and those with limited programming experience.
  • Be a cost-effective solution for web development, especially for small businesses or individuals, as it is open-source software that is free to use and distribute.
  • Provide high performance and speed, making it suitable for large and complex web applications. New features such as Just-In-Time (JIT) compilation in PHP 7 and later versions further improve the performance of the language.

With the Remi PHP repository, Fedora Linux allows for the seamless installation of various versions of PHP, a widely used open-source programming language for web development. The available versions include 8.2, 8.1, 8.0, and 7.4, which can be easily integrated with servers, databases, and technologies. This guide will provide instructions on properly installing these different versions of PHP on your Fedora Linux system.

Step 1: Update Fedora Linux

It is recommended to update the system before installing PHP and its extensions. The following commands can be run in a terminal to accomplish this.

sudo dnf upgrade --refresh

Step 2: Import PHP Remi Repository

Installing the Remi PHP repository on Fedora systems is a straightforward process, as it does not require EPEL like in the case of RHEL and its clones. Run the following command to import the Remi PHP repository corresponding to your Fedora version. The latest versions are provided, and this article will be updated as new Fedora releases become available.

Import Remi PHP Repository for Fedora 37

sudo dnf install -y

Import Remi PHP Repository for Fedora 36

sudo dnf install -y

Import Remi PHP Repository for Fedora 35

sudo dnf install -y

After installing, it’s important to check the installation is successful.

dnf repolist | grep remi

Example output:

[joshua@fedora-linux ~]$ dnf repolist | grep remi
remi                        Remi's RPM repository - Fedora 37 - x86_64
remi-modular                Remi's Modular repository - Fedora 37 - x86_64

Step 3: Enable PHP Remi Repository

Before diving in and installing different versions of PHP, it’s a good idea to check which versions are available in the REMI repository. By listing the available PHP modules first, you can get a better idea of what’s on offer and make a more informed decision about which version to install. It’s also worth noting that you’ll be able to change your selection later if needed, so don’t feel like you have to make a final decision immediately.

dnf module list php

You may be prompted to import the GPG key for Remi’s repository to proceed with the installation. If so, enter (Y) to continue.

Example output:

Now that you’ve looked at the available PHP versions, it’s time to run the command that will enable the version you want to install.

Enable PHP 8.2 on Fedora.

sudo dnf module enable php:remi-8.2 -y

Enable PHP 8.1 on Fedora.

sudo dnf module enable php:remi-8.1 -y

Enable PHP 8.0 on Fedora.

sudo dnf module enable php:remi-8.0 -y

Enable PHP 7.4 on Fedora.

sudo dnf module enable php:remi-7.4 -y

Step 4: Install PHP 8.2, 8.1, 8.0 or 7.4

You are ready to install PHP with the Remi PHP repository now enabled. The following options guide choosing between Apache and Nginx. However, if you know, you can further customize the installation by installing specific extensions for your CMS or software development needs.

Apache (httpd) PHP:

sudo dnf install php php-cli -y

Nginx PHP:

sudo dnf install php-fpm php-cli -y

To confirm that the installation of PHP was successful, you can run the following command after the installation process is finished.

php -v

If you wish, you can run the command below to acquire the most commonly used extensions for your chosen version of PHP. It’s important to note that you should remove any extensions you know will not be needed for your specific use case.

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

Another method to install the commands above is by using the format of PHP-{extension}.

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

The command below can be executed at any time to view the currently loaded modules.

php -m

It’s a good practice to keep an eye on the installed modules and remove any unnecessary ones, as too many installed modules can negatively impact system performance.

If you’re interested in installing the development branch of PHP, you can use the command provided below.

sudo dnf install php-devel

To install additional development tools like debugging, use the command below.

sudo dnf install php-xdebug php-pcov

It’s important to keep in mind that installing this version will add multiple dependencies, so it’s not recommended unless you have a specific need for it in your PHP development or a particular requirement.

Step 5: Set Up Nginx user for PHP-FPM

When installing PHP-FPM on Linux distributions such as Debian or Ubuntu, the “www-data” user is commonly used. However, this is not the case for installations on the RHEL family. The PHP-FPM service is default set up to run under the “Apache” user, which is incompatible with Nginx. As a result, adjustments need to be made to the configuration to ensure proper usage.

The first step is to open the configuration file (www.conf) using the below command.

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

Once the configuration file is open, you must replace the (Apache) user and group with the (Nginx) user and group.

Example from:

Example to:

To save, press (CTRL+O), then exit (CTRL+X).

After making the necessary adjustments, it’s time to restart your PHP-FPM service.

sudo systemctl restart php-fpm

Example Nginx PHP-FPM Server Block Code

For Nginx to handle PHP files, the server block needs to have a specific configuration, as shown in the example below. This example applies to all server{} blocks that handle PHP files, and it’s important to include “location ~ .php$.” in the configuration.

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;

To verify that the changes made to the previous code did not cause any errors, you can use the following command to test the Nginx configuration.

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

To complete the PHP-FPM setup, it’s necessary to restart the Nginx service.

sudo systemctl restart nginx


This guide has outlined the steps for installing PHP on Fedora Linux by utilizing the Remi PHP repository, setting the chosen version as the default, installing common extensions, and configuring the Nginx server block to process PHP files. It emphasized the importance of keeping track of dependencies and removing unnecessary modules. Additionally, it stressed the significance of testing Nginx for errors before restarting the service, particularly in a live production environment.

Share to...