Easy Steps To Upgrade PHP Version on AlmaLinux 8 and Rocky Linux 8
This tutorial intends to teach you to Upgrade PHP Version on AlmaLinux 8 and Rocky Linux 8. The default version of PHP that is available in AlmaLinux 8 and Rocky Linux 8 isn’t up to date. So we decided to provide this guide on the Orcacore website that you can use to update your PHP version to the latest version.
Here we assumed that you have PHP installed on your server, but it is not in the latest version. To update it, you must have access to your server as a non-root user with sudo privileges. For this purpose, you can visit the following initial guides:
Initial Server Setup with AlmaLinux 8
Initial Server Setup with Rocky Linux 8
In both servers, you can use the following instructions to Upgrade PHP Version on AlmaLinux 8 and Rocky Linux 8.

Step 1 – Check the Current PHP Version on AlmaLinux 8 and Rocky Linux 8
At this point, to show you the guide steps, we use AlmaLinux 8. Check the current PHP version installed on the server with the following command:
php -v
**Output**
PHP 7.2.24 (cli) (built: Oct 22 2019 08:28:36) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
As you can see, PHP 7.2 that is installed is out of date and you should Upgrade PHP Version on AlmaLinux 8 and Rocky Linux 8.
Step 2 – Install Remi Repository on AlmaLinux 8 and Rocky Linux 8
To upgrade your PHP version, you must install the Remi repository on your server.
Remi’s RPM repository is a free and stable YUM repository mainly for the PHP stack.
To do this, run the command below:
sudo dnf install http://rpms.remirepo.net/enterprise/remi-release-8.rpm
At this point, use the following command to install the yum-utils package:
sudo dnf install yum-utils -y
Step 3 – Update the PHP Version To The Latest
Next, you need to enable the Remi for the latest stable version of PHP. At the current time, the latest stable version of PHP is PHP 8.2. First, reset the default PHP module with the command below:
sudo dnf module reset php -y
Then, enable the Remi repo for PHP 8.2 with the command below:
sudo dnf module install php:remi-8.2 -y
Then, update your local package index:
sudo dnf update -y
Check your PHP version again:
php -v
**Output**
PHP 8.2.10 (cli) (built: Aug 29 2023 15:31:38) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.2.10, Copyright (c) Zend Technologies
with Zend OPcache v8.2.10, Copyright (c), by Zend Technologies
As you can see, PHP has been upgraded to the latest version.
Conclusion
At this point, you have learned to Upgrade PHP Version on AlmaLinux 8 and Rocky Linux 8. Because the default version of PHP in AlmaLinux 8 and Rocky Linux 8 is PHP 7.2 and it is out of date. So it is recommended to upgrade it.
Hope you enjoy it. Need any help or suggestions? Please comment for us.
Also, you may like to read the following articles:
cPanel Error ‘PHP PECL imagick fails on PHP 8.3’
What’s New in PHP 8.4? Release Date and Top Features Explained
Easy Steps To Run PHP 8.3 on Linux Mint 21
Best PHP 8.3 Installation on AlmaLinux 9 / Rocky Linux 9
Alternative Solutions for Upgrading PHP on AlmaLinux 8 and Rocky Linux 8
While the Remi repository method is a reliable way to upgrade PHP, there are alternative approaches that can be considered. Here are two different methods:
1. Using Software Collections (SCL)
Software Collections (SCL) allow you to install multiple versions of software on the same system without them conflicting. This is particularly useful when you need to maintain compatibility with older applications while also using newer PHP versions for new projects.
Explanation:
SCL provides a mechanism to install and manage different versions of software in isolated environments. Each software collection resides in /opt/rh/
, and you activate them using the scl enable
command. This method is advantageous because it allows you to have multiple PHP versions installed concurrently, which is beneficial for testing and compatibility purposes. It also ensures that the system’s default PHP version remains untouched, minimizing the risk of breaking existing applications. Upgrade PHP Version on AlmaLinux 8 and Rocky Linux 8 with SCL is a good choice.
Steps:
-
Install SCL repository:
sudo dnf install centos-release-scl -y
-
List available PHP versions in SCL:
sudo dnf module list php
This command will show you the available PHP modules. Look for modules like
php73
,php74
,php80
,php81
, etc. -
Install the desired PHP version:
For example, to install PHP 7.4, use:
sudo dnf install rh-php74 -y sudo dnf install rh-php74-php-fpm rh-php74-php-mysqlnd rh-php74-php-gd rh-php74-php-pear -y # Install common extensions
Replace
rh-php74
with the appropriate SCL name for your desired PHP version. Also, add any other PHP extensions you need. -
Enable the SCL:
scl enable rh-php74 bash
This command activates the PHP 7.4 environment in your current shell session.
-
Verify the PHP version:
php -v
You should now see PHP 7.4 as the active version in your shell.
-
Running PHP-FPM (if needed):
If you’re using PHP-FPM, you’ll need to start and enable the service specific to the SCL.
sudo systemctl start rh-php74-php-fpm sudo systemctl enable rh-php74-php-fpm
-
Integrating with Web Server (e.g., Apache):
You’ll need to configure your web server to use the PHP-FPM socket provided by the SCL. This usually involves modifying your virtual host configuration to point to the correct socket (e.g.,
/opt/rh/rh-php74/root/var/run/php-fpm/www.sock
).
Code Example (Apache Virtual Host Configuration):
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/example.com
<FilesMatch .php$>
SetHandler "proxy:unix:/opt/rh/rh-php74/root/var/run/php-fpm/www.sock|fcgi://localhost"
</FilesMatch>
<Directory /var/www/example.com>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/apache2/example.com_error.log
CustomLog /var/log/apache2/example.com_access.log combined
</VirtualHost>
2. Compiling from Source
Another approach is to compile PHP from source. This method offers the greatest flexibility, allowing you to customize compilation options and ensure compatibility with your specific system configuration. However, it requires more technical expertise and can be time-consuming.
Explanation:
Compiling from source involves downloading the PHP source code, configuring it with the desired options, and then building the executable. This gives you fine-grained control over the installation process and allows you to tailor PHP to your exact needs. However, it’s more complex than using package managers and requires you to manage dependencies manually. It also means you are responsible for future updates and security patches. Upgrade PHP Version on AlmaLinux 8 and Rocky Linux 8 by compiling it from the source is not easy.
Steps:
-
Install Development Tools and Dependencies:
sudo dnf groupinstall "Development Tools" -y sudo dnf install libxml2-devel bzip2-devel openssl-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel gmp-devel -y
Ensure you have all necessary dependencies for the PHP extensions you plan to use.
-
Download PHP Source Code:
Go to php.net and download the source code for the desired PHP version. Then, extract the archive:
wget https://www.php.net/distributions/php-8.2.10.tar.gz # Replace with the actual URL tar -xvzf php-8.2.10.tar.gz cd php-8.2.10
-
Configure the Build:
This is where you specify the options for your PHP installation. A typical configuration might look like this:
./configure --with-config-file-path=/usr/local/etc/php --with-mysqli --with-pdo-mysql --with-openssl --with-curl --with-gd --enable-mbstring --enable-zip --enable-bcmath --enable-opcache
Adjust the options to suit your needs. The
--with-config-file-path
option specifies where thephp.ini
file will be located. The--with-*
options enable specific extensions. The--enable-*
options enable core PHP features. Use./configure --help
to see a full list of available options. -
Compile and Install:
make sudo make install
This will compile PHP and install it to
/usr/local
by default. -
Configure PHP:
Copy the default
php.ini
file:cp php.ini-production /usr/local/etc/php/php.ini # Or php.ini-development
Edit the
php.ini
file to configure PHP settings. -
Configure Web Server:
You’ll need to configure your web server to use the newly compiled PHP version. This usually involves updating the web server configuration to point to the PHP-FPM socket or the PHP CLI executable.
Code Example (Bash Script for Compilation – Simplified):
#!/bin/bash
PHP_VERSION="8.2.10"
PHP_SOURCE="php-${PHP_VERSION}.tar.gz"
# Download and extract
wget "https://www.php.net/distributions/${PHP_SOURCE}"
tar -xvzf "${PHP_SOURCE}"
cd "php-${PHP_VERSION}"
# Configure
./configure
--with-config-file-path=/usr/local/etc/php
--with-mysqli
--with-pdo-mysql
--with-openssl
--enable-opcache
# Compile and install
make
sudo make install
# Copy php.ini
sudo cp php.ini-production /usr/local/etc/php/php.ini
echo "PHP ${PHP_VERSION} installed successfully!"
Considerations:
- Dependencies: Ensure all required dependencies are installed before compiling.
- Updates: You’ll need to manually update PHP by recompiling when new versions are released.
- Complexity: This method is more complex and requires a deeper understanding of PHP configuration.
Choosing the right method depends on your specific needs and technical expertise. The Remi repository offers a balance of ease of use and control, while SCL provides flexibility for managing multiple PHP versions. Compiling from source gives you the most control but requires more effort and expertise.