Share your love
How To Install PHP 8.1 on AlmaLinux 9

In this article, you will learn How To Install PHP 8.1 on AlmaLinux 9. PHP is an open-source, server-side programming language that can be used to create websites, applications, customer relationship management systems, and more. It is a widely used general-purpose language that can be embedded into HTML. This functionality with HTML means that the PHP language has remained popular with developers as it helps to simplify HTML code.
In this guide from the Orcacore website, you will learn to install the latest stable version of PHP on AlmaLinux 9. At the current time, PHP 8.1 is the latest stable version.
Table of Contents
Steps To Install PHP 8.1 on AlmaLinux 9
To complete this guide, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our article on the Initial Server Setup with AlmaLinux 9.
1. Install PHP Remi Repository on AlmaLinux 9
First, you need to update your local package index with the following command:
sudo dnf update -y
Then, you need to install the EPEL repository on AlmaLinux 9 with the command below:
sudo dnf install epel-release -y
Currently, PHP 8.1 is not featured in AlmaLinux’s AppStream. So you can install PHP from the Remi repository that deploys the latest PHP 8.1 builds. To do this, run the following command:
sudo dnf install dnf-utils https://rpms.remirepo.net/enterprise/remi-release-9.rpm
Again, update your local package index to update your repository:
sudo dnf update -y
2. Remove Older PHP Version From AlmaLinux 9
Now 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
3. Enable Remi PHP 8.1 Repository
To reset the PHP module list on AlmaLinux 9, you can use the following command:
sudo dnf module list reset php -y

Note: PHP 8.2 is available for testing at the time of writing this guide. Now you need to enable PHP 8.1 on AlmaLinux 9 with the command below:
sudo dnf module enable php:remi-8.1
4. Installing PHP 8.1 on AlmaLinux 9
At this point, you have added the Remi PHP repository and enabled PHP 8.1 to be the default version on your system. You can install PHP 8.1 with the following command:
sudo dnf install php -y
If you would like to install the most commonly used extensions for PHP 8.1, 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
Finally, you can use the following command for anyone interested in installing the development branch:
sudo dnf install php-devel -y
To verify your PHP 8.1 installation on AlmaLinux 9, you can check its version:
php -v

By default, on AlmaLinux 9, the PHP-FPM service is designed to be run Apache user. If you are using Nginx, you need to make configuration changes in (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
Installing PHP 8.1 on AlmaLinux 9 is straightforward and efficient using the Remi repository. With a few terminal commands, you can enable the necessary repositories and install PHP 8.1 along with essential extensions. This setup ensures compatibility with modern web applications while maintaining system stability and performance.
Hope you enjoy it. You may also like to read the following articles:
Installing PHP 8.3 on Debian 11
Install PHP 7.4 on Debian 12 Bookworm