Updating PHP on Red Hat Enterprise Linux 8 typically involves leveraging the Remi repository, as the default RHEL repositories might not always offer the latest PHP versions. Before you start, it’s crucial to back up your system and any PHP configurations or applications, as major PHP updates can introduce backward-incompatible changes.
Here’s a general guide to updating PHP on RHEL 8, with a focus on upgrading to PHP 8.x:
1. Prerequisites:
- Root or sudo access: You’ll need elevated privileges to install and manage packages.
- Internet connectivity: To download packages from repositories.
- Familiarity with DNF: Red Hat Enterprise Linux 8 uses
dnf
as its package manager.
2. Enable EPEL and Remi Repositories:
The Remi repository provides more recent PHP versions. It relies on the EPEL (Extra Packages for Enterprise Linux) repository.
# Install EPEL repository
sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
# Install Remi repository
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm
3. Reset and Enable the Desired PHP Module:
RHEL 8 uses DNF modules to manage different versions of software. You’ll need to reset the current PHP module and then enable the desired Remi PHP stream (e.g., remi-8.2
or remi-8.3
).
-
List available PHP modules:
sudo dnf module list php
This will show you the available PHP streams, including those from the Remi repository (e.g.,
php:remi-8.2
,php:remi-8.3
). -
Reset the default PHP module:
sudo dnf module reset php -y
This command unsets the currently enabled PHP module.
-
Enable the desired PHP version from Remi: For example, to enable PHP 8.2:
sudo dnf module enable php:remi-8.2 -y
Or for PHP 8.3:
sudo dnf module enable php:remi-8.3 -y
4. Install or Update PHP:
Now that the correct module stream is enabled, you can install or update PHP.
sudo dnf install php php-cli php-common -y
This command will install the core PHP packages. You’ll likely need additional PHP extensions depending on your application’s requirements (e.g., php-mysqlnd
, php-fpm
, php-gd
, php-xml
, etc.). You can install them with:
sudo dnf install php-{extension1,extension2,extension3} -y
# Example:
sudo dnf install php-{fpm,mysqlnd,gd,xml,mbstring} -y
5. Verify the PHP Version:
After installation, verify the installed PHP version:
php -v
You should see the version you enabled (e.g., PHP 8.2.x or PHP 8.3.x).
6. Configure PHP-FPM (if using with Nginx or Apache with FPM):
If you are using PHP with a web server like Nginx or Apache with PHP-FPM, you’ll need to start and enable the php-fpm
service:
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
sudo systemctl restart httpd # If using Apache
sudo systemctl restart nginx # If using Nginx
7. Test Your PHP Application:
Create a simple info.php
file in your web server’s document root (e.g., /var/www/html/info.php
) to confirm PHP is working correctly:
<?php
phpinfo();
?>
Then, access it from your web browser (e.g., http://your_server_ip/info.php
).
Important Considerations:
- Backward Incompatibility: PHP 8 introduces significant changes, and your existing PHP 7.x code might not be fully compatible. Thoroughly test your applications after the upgrade. Refer to the official PHP migration guides (e.g., https://www.php.net/manual/en/migration80.php) for details on incompatible changes.
- Extensions: Ensure all necessary PHP extensions for your applications are installed and compatible with the new PHP version.
- Configuration Files: Your
php.ini
configuration might need adjustments. - Multiple PHP Versions (Advanced): While the above steps replace the default PHP, it is possible to run multiple PHP versions on the same RHEL 8 server using Software Collections (SCLs) or by configuring different PHP-FPM pools. This is a more complex setup often used for environments with diverse application requirements.
- Red Hat Subscription: For official Red Hat support, you’d typically rely on the PHP versions provided by Red Hat’s AppStream, which might be older. The Remi repository is a community-maintained resource that provides newer versions.
Always perform these steps in a development or staging environment before applying them to a production server.