Table of Contents[Hide][Show]
In this tutorial, we will learn how to install PHP 8.4 on RHEL 9 in easy-to-follow steps.
PHP is one of the most widely used server-side scripting languages for web development, known for its simplicity, flexibility, and robust support for dynamic content. If you’re a developer, you probably rely on PHP to build and manage web applications such as content management systems (CMS) like WordPress and Drupal. As of today, PHP 8.4 is the latest stable version, offering enhanced performance, security improvements, and new features that are ideal for production environments.
If you’re using RHEL 9 (Red Hat Enterprise Linux) and want to install PHP 8.4 on your system, this guide is for you. We will walk you through the entire installation process, making sure it’s clear and easy to follow. This guide will also cover how to enable the necessary repositories, install additional PHP modules, and verify the installation.
Prerequisites
Before proceeding with the installation of PHP 8.4 on RHEL 9, ensure the following:
- You have a running RHEL 9 system.
- You have shell access with a user account that has sudo privileges to install software.
- You have a stable internet connection to download the necessary packages.
How to Install PHP 8.4 on RHEL 9
Step 1: Update System Packages
To ensure that your system is up to date and that all packages are current, it’s a good idea to update the system first. This reduces the risk of encountering compatibility issues during the installation of PHP 8.4. The following command will update all existing packages to the latest available versions from the repositories:
sudo dnf update
Once the update is complete, it’s always wise to check for any system inconsistencies or potential problems, especially on production servers, before moving forward.
Step 2: Enable RPM Repositories
To install PHP 8.4 on RHEL 9, we will use the REMI repository, which is widely trusted for providing PHP packages, along with the EPEL (Extra Packages for Enterprise Linux) repository. These two repositories are required for managing and installing PHP versions on RHEL 9.
First, you need to install the EPEL repository using the following command:
sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
Next, install and enable the REMI repository by running:
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm
Once the repositories are enabled, you can proceed with installing PHP 8.4 on your RHEL 9 system.
Step 3: Install PHP 8.4
Now that you have the necessary repositories set up, the next step is to install PHP 8.4. The REMI repository provides multiple PHP versions through modules, so you need to enable the PHP 8.4 module before installing it. To enable the PHP 8.4 module, use the following command:
sudo dnf module enable php:remi-8.4
This will enable PHP 8.4 and set it up for installation. If for any reason the installation doesn’t automatically begin after enabling the module, you can manually install PHP by running:
sudo dnf install php
The system will proceed to install PHP 8.4 along with its dependencies.
Once the installation is complete, verify that PHP 8.4 has been installed correctly by checking the PHP version:
php -v
The output should display the PHP version as PHP 8.4.x, confirming that PHP 8.4 has been installed successfully on your system.
Step 4: Install Additional PHP Modules
Most applications that run on PHP rely on additional modules for various functionalities. For example, you may need modules for working with databases, image manipulation, or XML parsing. Some of the most commonly used PHP modules include:
- php-gd for image manipulation.
- php-mysqlnd for MySQL database support.
- php-xml for XML parsing.
- php-soap for SOAP protocol support.
You can search for available PHP modules using the following command:
sudo dnf search php-*
This will list all available PHP-related modules. You can then install the required modules using the dnf
command. For example, to install the commonly used modules mentioned above, run:
sudo dnf install php-gd php-mysqlnd php-xml php-soap
Repeat this step for any additional PHP modules that your application requires.
Step 5: Test PHP Installation
To test whether PHP 8.4 is working correctly on your RHEL 9 system, you can create a simple PHP test script. This will help verify that the PHP interpreter is functioning as expected.
- First, navigate to your web server’s root directory (e.g.,
/var/www/html
) or any other directory that is accessible via your web server. - Create a new file named
info.php
:
sudo nano /var/www/html/info.php
- Add the following PHP code to the
info.php
file:
- Save the file and exit the text editor.
Now, open a web browser and navigate to the following URL:
http:///info.php
If PHP 8.4 is installed correctly, you will see the PHP information page, which provides detailed information about the PHP installation, including the version and configuration settings.
Step 6: Secure the PHP Info File
Once you’ve confirmed that PHP is working, it’s a good practice to remove the info.php
file for security reasons. Leaving such files on your server can expose sensitive information about your server’s configuration.
To remove the file, run:
sudo rm /var/www/html/info.php
Conclusion
In this tutorial, we’ve covered the complete process of installing PHP 8.4 on RHEL 9, from setting up the required repositories to installing PHP and additional modules, and finally testing the installation. With PHP 8.4 successfully installed, you can now leverage the latest features, security improvements, and enhanced performance for your web applications.
Remember, keeping PHP up to date is essential for maintaining the security and performance of your applications. By following the steps outlined in this guide, you can ensure that your RHEL 9 system is ready to run PHP 8.4 in a secure and efficient environment.
If you encounter any issues or need further assistance, don’t hesitate to consult the official PHP documentation or explore other community-driven resources. Enjoy coding with PHP 8.4!
FAQs: How to Install PHP 8.4 on RHEL 9
What are the prerequisites for installing PHP 8.4 on RHEL 9?
Before installing PHP 8.4 on RHEL 9, ensure you have:
- A RHEL 9 system with root or sudo user access.
- The system updated to the latest version using
sudo dnf update
. - Optional: Access to the Remi repository for the latest PHP packages.
How do I enable the Remi repository for installing PHP 8.4 on RHEL 9?
To enable the Remi repository:
Install the EPEL repository:
bashCopy code
Enable the Remi repository:
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm
List available PHP streams:
sudo dnf module list php
How to install PHP 8.4 on RHEL 9 step by step?
To install PHP 8.4 on RHEL 9:
- Reset the current PHP module:
sudo dnf module reset php
- Enable the PHP 8.4 module:
sudo dnf module enable php:8.4
- Install PHP 8.4 and common extensions:
sudo dnf install php php-cli php-fpm php-mysqlnd
- Verify the installation:
php -v
What common issues might occur during PHP 8.4 installation on RHEL 9?
When installing PHP 8.4 on RHEL 9, you might encounter:
- Dependency errors: Ensure all repositories (EPEL, Remi) are properly configured.
- Version mismatch: Double-check if PHP 8.4 is available in the Remi repository for RHEL 9.
- Permission issues: Run all commands with
sudo
or as the root user.
Can I run multiple PHP versions alongside PHP 8.4 on RHEL 9?
Yes, you can. Using tools like php-fpm
or configuring separate PHP installations allows running multiple versions side by side. However, ensure that your web server (e.g., Apache or Nginx) is configured to handle multiple versions.
How do I configure Apache to use PHP 8.4 on RHEL 9?
After installing PHP 8.4 on RHEL 9, configure Apache to use it:
- Install the Apache PHP module:
sudo dnf install php
- Restart Apache to apply changes:
sudo systemctl restart httpd
- Test the configuration by creating a PHP info file:
echo " /var/www/html/info.php
- Access the file via your browser:
http://your-server-ip/info.php
.
How do I configure Nginx with PHP 8.4 on RHEL 9?
To configure Nginx with PHP 8.4:
- Install PHP-FPM:
sudo dnf install php-fpm
- Edit the Nginx configuration file to pass PHP requests to PHP-FPM:
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
- Restart Nginx and PHP-FPM:
sudo systemctl restart nginx php-fpm
How do I install PHP extensions for PHP 8.4 on RHEL 9?
To install extensions for PHP 8.4 on RHEL 9:
- Search for available extensions:
sudo dnf search php-
- Install the desired extension:
sudo dnf install php-
- Restart your web server to load the extension:
sudo systemctl restart httpd
How can I update an existing PHP installation to PHP 8.4 on RHEL 9?
To update to PHP 8.4:
- Reset the current PHP module:
sudo dnf module reset php
- Enable PHP 8.4:
sudo dnf module enable php:8.4
- Install PHP 8.4:
sudo dnf install php
How do I verify the successful installation of PHP 8.4 on RHEL 9?
To confirm PHP 8.4 installation:
- Check the PHP version:
php -v
This should display PHP 8.4 and its build details.
- Create a PHP info file as mentioned in FAQ #6 and access it in your browser to verify installation and extensions.