Install PHP 8.2 on AlmaLinux 9: Best Server Side Scripting
In this guide, we will explore How To Install PHP 8.2 on AlmaLinux 9. PHP is a server-side scripting language that is used to develop static websites, dynamic websites, or web applications. PHP stands for Hypertext Pre-processor, a name that evolved from its original designation as Personal Home Pages.
Currently, PHP 8.2 is the latest stable release of PHP. This article provides a step-by-step guide to installing it on your AlmaLinux 9 server, brought to you by Orcacore.
To successfully complete this guide, you must log in to your server as a non-root user with sudo privileges. If you haven’t already done so, you can follow our guide on Initial Server Setup with AlmaLinux 9.
Install Dependencies For PHP 8.2 Setup
First, update your local package index using the following command:
sudo dnf update -y
Install EPEL Repository
Next, install the EPEL (Extra Packages for Enterprise Linux) repository on AlmaLinux 9. This repository provides additional packages not available in the base AlmaLinux repositories. Use the following command:
sudo dnf install epel-release -y
Install PHP 8.2 Remi Repository
PHP 8.2 isn’t featured in AlmaLinux’s AppStream by default. Therefore, we will install PHP from the Remi repository, which provides the latest PHP 8.2 builds. Execute the following command:
sudo dnf install -y dnf-utils http://rpms.remirepo.net/enterprise/remi-release-9.rpm
Update your local package index again to include the newly added repository:
sudo dnf update -y
Remove Previous Versions of PHP
If you have previous versions of PHP and PHP-FPM installed, remove them to avoid conflicts. Use the following commands:
sudo dnf remove php php-fpm -y
Then, remove any remaining PHP-related package extensions:
sudo dnf remove php* -y
PHP Module List on AlmaLinux 9
Reset the PHP module list on AlmaLinux 9 to ensure a clean installation:
sudo dnf module list reset php -y

As illustrated above, the (d) tag indicates the default PHP version (likely PHP 8.1). We need to reset this and enable PHP 8.2.
Enable PHP 8.2 on AlmaLinux 9 using the following command:
sudo dnf module enable php:remi-8.2
Install PHP 8.2 on AlmaLinux 9
Now that the Remi PHP repository is added and PHP 8.2 is enabled, install PHP 8.2 with the following command:
sudo dnf install php -y
Install commonly used extensions for PHP 8.2 with this 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
For developers, install the development branch using this command:
sudo dnf install php-devel -y
Verify your PHP 8.2 installation on AlmaLinux 9 by checking the version:
php -v

Configure PHP-FPM Service
By default, the PHP-FPM service on AlmaLinux 9 is configured to run under the (Apache) user. If you’re using Nginx, you’ll need to adjust the configuration in www.conf
.
Open the file with your preferred text editor (e.g., vi):
sudo vi /etc/php-fpm.d/www.conf
Locate the user
and group
directives and change them to nginx
, as shown below:
user = nginx
group = nginx
Save and close the file.
Reload the PHP-FPM service to apply the changes:
sudo systemctl restart php-fpm
The Nginx server block requires the following configuration to process PHP files.
The following example should be added to all server {} blocks that process PHP files, specifically the location ~ .php$
block:
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 further information, consult the PHP Documentation page.
Conclusion
You have now successfully learned How To Install PHP 8.2 on AlmaLinux 9. PHP is a powerful tool for developing static websites, dynamic websites, and web applications. Install PHP 8.2 on AlmaLinux 9 and experience its power!
Alternative Solutions for Installing PHP 8.2 on AlmaLinux 9
While the Remi repository method outlined above is a common and effective approach to Install PHP 8.2 on AlmaLinux 9, alternative solutions exist. Here are two different ways to achieve the same goal, offering different trade-offs in terms of complexity and control.
1. Using a Software Collection Library (SCL)
Software Collections (SCLs) allow you to install multiple versions of the same software on a single system without conflicts. This is particularly useful when you need to support applications that require different PHP versions. The process is a bit more involved, but it offers excellent isolation.
Explanation:
SCLs work by creating isolated environments for each software version. This means that the PHP 8.2 installation will have its own set of binaries and libraries, preventing conflicts with the system’s default PHP version (if any). While AlmaLinux 9 doesn’t have a readily available SCL for PHP 8.2 in its base repositories, we can leverage the Remi repository to provide the necessary SCL packages. This allows to Install PHP 8.2 on AlmaLinux 9 effectively.
Steps:
-
Enable the Remi SCL Repository: This step is similar to the original method. We will leverage the Remi repository. Follow the same steps as before to add the Remi repository and enable it (as detailed in the original guide up to the ‘Remove Previous Versions of PHP’ section).
-
Install PHP 8.2 using SCL: Instead of directly installing PHP, install the PHP 8.2 SCL package:
sudo dnf install php82 -y
This command installs PHP 8.2 within an SCL environment.
-
Enable the SCL Environment: To use PHP 8.2, you need to activate the SCL environment. You can do this using the
scl enable
command. For example:scl enable php82 bash
This command opens a new shell with the PHP 8.2 environment activated. Any PHP commands executed within this shell will use PHP 8.2. To make this persistent, you can add the
scl enable
command to your.bashrc
or.zshrc
file. -
Verify the Installation: Check the PHP version within the SCL environment:
php -v
You should see the output indicating PHP 8.2.
Code Example:
The key here is the scl enable
command. Here’s an example of how to make the PHP 8.2 SCL environment persistent for a specific user:
echo "scl enable php82 bash" >> ~/.bashrc
source ~/.bashrc
This adds the scl enable
command to the user’s .bashrc
file, ensuring that the PHP 8.2 environment is activated whenever the user logs in.
2. Compiling from Source
Another alternative is to compile PHP 8.2 directly from the source code. This provides the most control over the installation process and allows you to customize PHP to your specific needs. However, it is also the most complex and time-consuming method.
Explanation:
Compiling from source involves downloading the PHP 8.2 source code, configuring the build process, and then compiling and installing the binaries. This allows you to specify the exact compilation flags, extensions to include, and installation directory. However, it also requires a good understanding of the build process and the necessary dependencies. This will also Install PHP 8.2 on AlmaLinux 9.
Steps:
-
Install Development Tools: You’ll need a C compiler (like GCC), make, and other development tools.
sudo dnf groupinstall "Development Tools" -y
-
Install Required Dependencies: PHP has many dependencies. You’ll need to install these before compiling. The exact dependencies will depend on the extensions you want to enable. A basic set of dependencies includes:
sudo dnf install libxml2-devel bzip2-devel libcurl-devel libpng-devel libjpeg-turbo-devel freetype-devel gmp-devel openssl-devel -y
-
Download the PHP 8.2 Source Code: Download the source code from the official PHP website (https://www.php.net/downloads).
wget https://www.php.net/distributions/php-8.2.0.tar.gz # Replace with the actual version tar -xzf php-8.2.0.tar.gz cd php-8.2.0
-
Configure the Build: Use the
./configure
script to configure the build process. This script checks for dependencies and sets up the Makefile. You’ll need to specify the extensions you want to enable using the--with-*
and--enable-*
options. For example:./configure --with-curl --with-gd --with-mysqli --enable-mbstring --with-openssl --prefix=/usr/local/php82
Here,
--prefix
specifies the installation directory. -
Compile and Install: Run
make
to compile the source code, and thenmake install
to install the binaries.make sudo make install
-
Configure Environment Variables: Add the PHP 8.2 binaries to your
PATH
environment variable and configure thephp.ini
file.export PATH=$PATH:/usr/local/php82/bin cp php.ini-production /usr/local/php82/lib/php.ini #Or php.ini-development
-
Create a PHP Info file
Create an info.php file on the server and enter the following:<?php phpinfo(); ?>
-
Access the PHP Info page in the browser
Navigate to the location of the PHP info page using a web browser.
Code Example:
Here’s a simplified example of a script to automate the build process:
#!/bin/bash
# Download PHP 8.2 source
wget https://www.php.net/distributions/php-8.2.0.tar.gz
tar -xzf php-8.2.0.tar.gz
cd php-8.2.0
# Configure the build
./configure --with-curl --with-gd --with-mysqli --enable-mbstring --with-openssl --prefix=/usr/local/php82
# Compile and install
make
sudo make install
# Configure environment variables
export PATH=$PATH:/usr/local/php82/bin
cp php.ini-production /usr/local/php82/lib/php.ini
echo "PHP 8.2 installed in /usr/local/php82"
Important Considerations:
- Dependencies: Managing dependencies can be challenging when compiling from source. Ensure you have all the necessary libraries and development headers installed.
- Security Updates: You’ll be responsible for manually applying security updates when compiling from source.
- Complexity: This method requires a deeper understanding of the PHP build process.
While compiling from source offers the most control, it’s generally recommended for advanced users who need specific customizations or are comfortable managing the build process. For most users, the Remi repository method or the SCL method provide a simpler and more convenient way to Install PHP 8.2 on AlmaLinux 9.