How to Install PHP on Fedora 39, 38 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.

Import Remi RPM Repository

Step 1: Update Fedora Linux Before PHP Installation

Update the system before you install PHP and its extensions. Run the following commands in a terminal to achieve this:

sudo dnf upgrade --refresh

Step 2: Import PHP Remi RPM Repository

To install the Remi PHP repository on Fedora systems, follow this simple process. Unlike RHEL and its clones, Fedora doesn’t need EPEL. To import the Remi PHP repository that matches your Fedora version, execute the command below:

We provide the latest versions, and we will update this article when new Fedora releases come out back on this article.

sudo dnf install -y
sudo dnf install -y
sudo dnf install -y

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

sudo dnf module list php

To proceed with the installation, the system might prompt you to import the GPG key for Remi’s repository.

If it does, 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.
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:

sudo dnf module enable php:remi-8.3 -y
sudo dnf module enable php:remi-8.2 -y
sudo dnf module enable php:remi-8.1 -y
sudo dnf module enable php:remi-8.0 -y
sudo dnf module enable php:remi-7.4 -y

Step 4: Install PHP 8.3, 8.2, 8.1, 8.0 or 7.4 via DNF Command

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 the successful installation of PHP, run the following command after finishing the installation process.

php -v

You can run the command below if you want to obtain the most commonly used extensions for your chosen version of PHP. However, make sure to remove any extensions that you know you won’t need 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}

You can execute the command below 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.

To install the development branch of PHP, 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

Remember that installing this version will add multiple dependencies. We don’t recommend it unless you specifically need it for your PHP development or have a particular requirement.

Additional: Configure Nginx User for PHP-FPM on Fedora

When you install PHP-FPM on Linux distributions like Debian or Ubuntu, you commonly use the “www-data” user. However, you don’t do this for installations in the RHEL family. By default, the PHP-FPM service runs under the “Apache” user, which doesn’t work with Nginx. Therefore, you must adjust the configuration for correct usage.

First, open the configuration file (www.conf) with the following command:

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

Open the configuration file and replace the (Apache) user and group with the (Nginx) user and group.

Screenshot illustrating the process of switching from Apache to PHP-FPM on Fedora Linux.
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.
Visual demonstration of setting up PHP-FPM to operate under the Nginx user on Fedora Linux.

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

Make the necessary adjustments, then restart your PHP-FPM service.

sudo systemctl restart php-fpm

Example Nginx PHP-FPM Server Block Code

To handle PHP files with Nginx, you must configure the server block as shown in the example below. Use this example for all server{} blocks that manage PHP files, and ensure you 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.

2 thoughts on “How to Install PHP on Fedora 39, 38 Linux”

  1. switching a version on Linux fedora 6.5.12-100.fc37.x86_64 #1 SMP PREEMPT_DYNAMIC Mon Nov 20 22:28:44 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
    doesn´t work. php -v reports 8.1.24 whatever i enter


Leave a Comment