Share your love
Easy Guide to Install PHP 7.4 on AlmaLinux 9

This guide intends to teach you to Install PHP 7.4 on AlmaLinux 9. PHP 7.4 was released on November 28, 2019, and it’s the last version before PHP 8. It brings lots of new features, syntax additions, and fixes.
Here are the most interesting PHP 7.4 changes to be aware of:
- Arrow functions for cleaner one-liner functions
- Preloading to improve performance
- Typed properties in classes
- Improved type variance
- The null coalescing assignment operator as a shorthand
- FFI for better extension development in PHP
- Underscores can be used to format numeric values
- Spread operator in arrays etc.
PHP 7.4 is an old version, but in some use cases, you may need to install an older version. To Install PHP 7.4 on AlmaLinux 9, you can proceed to the following steps provided by the Orcacore website.
Tips: To get a more recent version of PHP, you can check this guide on PHP 8.3 Installation on AlmaLinux 9 / Rocky Linux 9.
Table of Contents
Steps To Install PHP 7.4 on AlmaLinux 9
To install PHP 7.4 on AlmaLinux 9, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide the Initial Server Setup with AlmaLinux 9.
Now follow the steps below to Install PHP 7.4 on AlmaLinux 9.

Set up PHP 7.4 on AlmaLinux 9
First, you need to update your local package index with the following command:
sudo dnf update -y
Remove Old Versions of PHP
Then, you need to remove the PHP and PHP-FPM previous versions if you have them installed on your server. To do this, run the following command:
sudo dnf remove php php-fpm -y
Then remove the rest of the package extensions with the command below:
sudo dnf remove php* -y
Install Epel and Remi Repositories
At this point, you need to install Epel and Remi repos on your server by using the commands below:
# sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
# sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm
List PHP Versions
Now you can use the command below to list the available PHP versions:
sudo dnf module list php -y
Output
AlmaLinux 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
As you can see above, the (d) tag is next to PHP 8.1, which you will need to reset and change to Install PHP 7.4 on AlmaLinux 9.
Install PHP 7.4 on AlmaLinux
Now you need to enable and install PHP 7.4 on AlmaLinux 9 with the command below:
sudo dnf module install php:remi-7.4 -y
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-imap 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
To verify your PHP 7.4 installation on AlmaLinux 9, you can check its version:
php -v
Output
PHP 7.4.33 (cli) (built: Dec 19 2022 13:12:58) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
Configure PHP-FPM To Run As an Nginx User
By default on AlmaLinux 9, the PHP-FPM service is designed to be run by (Apache) user. If you are using Nginx you need to make configuration changes at (www.conf).
You can open the file with your favorite text editor, here we use vi:
sudo vi /etc/php-fpm.d/www.conf
Find the user and group directives and change them to Nginx as shown below:
user = nginx
group = nginx
When you are done, save and close the file.
Reload the PHP-FPM service to apply the changes:
sudo systemctl restart php-fpm
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.
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;
}
For more information, you can visit the PHP Documentation page.
Conclusion
At this point, you have learned to Install PHP 7.4 on AlmaLinux 9. As we said, PHP 7.4 is a little bit old version. But to set up and run some applications you may need older versions of PHP. By following the guide steps, you can easily set up PHP 7.4 on your AlmaLinux 9.
Hope you enjoy it. You may like these articles too:
Upgrade Default PHP to PHP 8.3 in Debian / Ubuntu
Find Apache and PHP Version Installed on Linux