In the following tutorial, you will learn how to import the REMI PHP Module and install PHP 7.4 on Fedora 37/36/35 server or workstation desktop, 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 on Fedora Linux
PHP 7.4 is no longer featured in Fedora because Fedora supports 8.x onwards. You will need to import the REMI PHP repository to install the PHP 7.4 version and keep it up-to-date.
First, import and install the Remi repo; use the following terminal command. Remember, match the Remi repo to your Fedora distribution version.
Import Remi PHP Repository for Fedora 37
sudo dnf install http://rpms.remirepo.net/fedora/remi-release-37.rpm -y
Import Remi PHP Repository for Fedora 36
sudo dnf install http://rpms.remirepo.net/fedora/remi-release-36.rpm -y
Import Remi PHP Repository for Fedora 35
sudo dnf install http://rpms.remirepo.net/fedora/remi-release-35.rpm -y
Next, verify the installation.
dnf repolist | grep remi
Example output:
[[email protected] ~]$ dnf repolist | grep remi
remi Remi's RPM repository - Fedora 37 - x86_64
remi-modular Remi's Modular repository - Fedora 37 - x86_64
Situational – Remove Existing PHP Install on Fedora Linux
Remove the previous version for users wanting to install PHP 7.4 but have already installed PHP or PHP-FPM. For example, remove PHP 7.3 for PHP 7.4.
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 7.4 (Remi) Repository on Fedora Linux
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
You will be prompted to import the GPG key for Remi’s repository. Type (Y) to proceed if you encounter it.
Next, enable PHP 7.4 with the following command:
sudo dnf module enable php:remi-7.4 -y
Example output:
============================================================================
Package Architecture Version Repository Size
============================================================================
Enabling module streams:
php remi-7.4
Transaction Summary
============================================================================
Install PHP 7.4 on Fedora Linux
Now that you have added the Remi PHP repository and enabled PHP 7.4 to be the default version on your Fedora system, you can install PHP 7.4 with the following command:
Apache (httpd) Users:
sudo dnf install php -y
Nginx Users:
sudo dnf install php-fpm -y
Optionally, if you would like to install the most commonly used extensions for PHP 7.4, 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 highly recommended to only install and keep what modules you require from a performance and security standard.
You can use the following command to view modules loaded at any time.
php -m
Example output (They will 100% vary):
[PHP Modules]
apcu
bcmath
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
igbinary
imagick
intl
json
libxml
mbstring
memcache
memcached
msgpack
mysqli
mysqlnd
openssl
pcntl
pcov
pcre
PDO
pdo_mysql
Phar
readline
redis
Reflection
session
SimpleXML
sockets
SPL
sqlite3
standard
tokenizer
xdebug
xml
xmlreader
xmlrpc
xmlwriter
xsl
Zend OPcache
zip
zlib
[Zend Modules]
Xdebug
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 7.4 and the extensions, check the version with the following command:
php -v
Example output:
[[email protected] ~]$ php -v
PHP 7.4.33 (cli) (built: Oct 31 2022 10:36:05) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies
PHP-FPM Installations of PHP 7.4 on Fedora Linux
Unlike PHP-FPM installations on Debian/Ubuntu that use the (www-data) user, this isn’t the case with RHEL family installations. By default on Fedora, the PHP-FPM service is designed to be run by (Apache) user, which is incorrect since we are using Nginx, which needed 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.
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
Conclusion
This tutorial demonstrated installing PHP 7.4 on Fedora Linux using the command line terminal. The tutorial on how to add the REMI RPM PHP Fusion repository to maintain the latest version of PHP. After completing this tutorial, you should understand how to install and configure PHP on your Fedora server. You can begin developing dynamic websites and applications with PHP or running your website stack, such as LEMP (Nginx, PHP, MariaDB).