Install PHP 8.3, 8.2, 8.1, 8.0 or 7.4 on Fedora 39/38/37 Linux

For those aiming to install PHP 8.3, 8.2, 8.1, 8.0, or 7.4 on Fedora, understanding the significance and versatility of PHP is paramount. PHP, standing for Hypertext Preprocessor, has cemented its place as an indispensable open-source programming language tailored for web development. Let’s delve into the myriad advantages PHP brings to the table:

Key Advantages of PHP:

  • Dynamic Web Pages: PHP excels in server-side scripting, paving the way for dynamic web content and bolstered security measures.
  • Cross-Platform Compatibility: PHP seamlessly integrates with various operating systems, including Windows, Mac, and Linux, underscoring its adaptability.
  • Robust Community Support: A thriving community of PHP developers ensures constant resources, tutorials, and troubleshooting assistance.
  • Comprehensive Built-in Functions: PHP has many functions to facilitate everyday web tasks, from database connectivity to email dispatch.
  • Database Integration: PHP’s compatibility with renowned databases like MySQL and PostgreSQL streamlines database-centric projects.
  • Interactivity with Modern Tech: PHP’s synergy with technologies like JavaScript and AJAX fosters the creation of dynamic, user-friendly web applications.
  • Library & Framework Access: PHP’s ecosystem boasts libraries and frameworks like Laravel and CodeIgniter, simplifying and accelerating development processes.
  • Beginner-Friendly: PHP’s intuitive syntax and structure make it an ideal starting point for budding developers.
  • Cost-Effective Development: Being open-source, PHP is a budget-friendly choice for businesses and individual developers.
  • Optimized Performance: PHP ensures swift, efficient performance, further enhanced by features like JIT compilation in its newer versions.

For Fedora users, the integration of PHP, especially versions 8.3, 8.2, 8.1, 8.0, and 7.4, is straightforward, thanks to the Remi PHP repository. The subsequent guide will elucidate the steps to seamlessly install these PHP versions on Fedora, ensuring your web development journey is well-equipped.

One year after the release of PHP 7.3, PHP version 7.4.33 marked the last official release of PHP 7.4. For those prioritizing a secure installation, it’s strongly recommended to upgrade to a maintained version.

For those wanting further information on PHP 8.x:

  • PHP 8.0, currently under security-only support, will be maintained until November 2023.
  • PHP 8.1 has active support and is set to be maintained until November 2023, with security support extending to 2024.
  • PHP 8.2 will have active support and will be maintained until December 2024, with security support continuing through 2025.

Step 1: Update Fedora Linux Before PHP Installation

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 39

sudo dnf install -y

Import Remi PHP Repository for Fedora 38

sudo dnf install -y

Import Remi PHP Repository for Fedora 37

sudo dnf install -y

Import Remi PHP Repository for Fedora 36

sudo dnf install -y

Step 3: Enable PHP Remi Repository on Fedora

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 can change your selection later if needed, so don’t feel you must make a final decision immediately.

sudo 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.

Screenshot displaying the listing of PHP versions 8.3, 8.2, 8.1, 8.0, and 7.4 on Fedora Linux using the Remi PHP RPM repository.Pin
Visual demonstration of available PHP versions on Fedora Linux when using the Remi PHP RPM repository.

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

Install PHP 8.3 on Fedora

sudo dnf module enable php:remi-8.3 -y

Install PHP 8.2 on Fedora

sudo dnf module enable php:remi-8.2 -y

Install PHP 8.1 on Fedora

sudo dnf module enable php:remi-8.1 -y

Install PHP 8.0 on Fedora

sudo dnf module enable php:remi-8.0 -y

Install PHP 7.4 on Fedora

sudo dnf module enable php:remi-7.4 -y

Step 4: Install PHP 8.3, 8.2, 8.1, 8.0 or 7.4 on Fedora

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 using the PHP-{extension} format.

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 anytime 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 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 remember 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.

Additional: Configure Nginx User for PHP-FPM on Fedora

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, the configuration needs to be adjusted 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:

Screenshot illustrating the process of switching from Apache to PHP-FPM on Fedora Linux.Pin
A step-by-step visual guide on how to transition from using Apache to PHP-FPM on Fedora Linux.

Example to:

Screenshot showcasing the configuration of PHP-FPM to run as the Nginx user on Fedora Linux.Pin
Visual demonstration of setting up PHP-FPM to operate under the Nginx user on Fedora Linux.

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 with Fedora

For Nginx to handle PHP files, the server block must have a specific configuration, as shown in the example below. This example applies to all server{} blocks that handle PHP files, and it’s essential 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...