Website Vidya
Linux & ServersStep-by-Step Guide

How to Install PHP 8.4 on RHEL 9: Easy Steps

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 ...

RR
Rajesh RayLead Systems Educator
Published:
4 min read
How to Install PHP 8.4 on RHEL 9: Easy Steps
AI Executive SummaryCORE CIS AI

4 min read

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 ...

Key Highlights
  • Prerequisites
  • How to Install PHP 8.4 on Ubuntu 24.04
  • Conclusion
Grounded in full engineering runbookCORE CIS Ai Engine

PHP (Hypertext Preprocessor) is a widely-used, open-source, server-side scripting language designed for web development. It is especially suited for creating dynamic web pages and applications.

This comprehensive tutorial will guide you through how to install PHP 8.4 on Ubuntu 24.04. Whether you're a beginner setting up your first server or an experienced developer upgrading your environment, this guide will cover every step.

Prerequisites

Before proceeding with the installation of PHP 8.4 on Ubuntu 24.04, ensure the following:

  • You have a running Ubuntu 24.04 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 Ubuntu 24.04

Step 1: Update Your Operating System

Before installing any new packages, it's important to ensure that your Ubuntu 24.04 operating system is fully up to date. This helps to avoid compatibility issues and ensures a smoother installation process. Run the following commands to update and upgrade all existing packages:

Advertisement
sudo apt update && sudo apt upgrade -y

This command updates the package lists and upgrades installed packages to their latest versions.

Step 2: Add the PHP Repository

The default Ubuntu 24.04 repository does not include PHP 8.4. To install it, you will need to add the Ondrej Sury PPA repository, which is widely trusted for hosting PHP packages.

Install Required Packages

Before adding the repository, install the necessary packages that enable secure communication and repository management:

sudo apt-get install -y ca-certificates apt-transport-https software-properties-common

Add the PPA Repository

With the required packages installed, add the Ondrej Sury PPA:

sudo add-apt-repository ppa:ondrej/php

Press Enter when prompted to confirm the addition of the repository.

Advertisement

Update the Repository List

After adding the PPA, refresh the package list to include the new repository:

sudo apt-get update

Step 3: Install PHP 8.4

With the repository added, you can now install PHP 8.4 on your system.

Install PHP 8.4

Run the following command to install PHP 8.4:

sudo apt-get install -y php8.4

Verify the Installation

Once the installation is complete, verify the PHP version installed:

php8.4 --version

Expected Output:

Advertisement
PHP 8.4.1 (cli) (built: Nov 21 2024 14:54:00) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.1, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.1, Copyright (c), by Zend Technologies

This output confirms that PHP 8.4 has been successfully installed.

Step 4: Install PHP 8.4 for Apache

If you're using Apache as your web server, you'll need to install the PHP 8.4 module and configure Apache to use it.

Install the PHP Module for Apache

Run the following command to install the Apache PHP module:

sudo apt install -y libapache2-mod-php8.4

Restart Apache

After installation, restart Apache to enable the new PHP module:

sudo systemctl restart apache2

Test the Installation

Create a test PHP file to verify that PHP is working with Apache:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Open a web browser and navigate to:

http://your-server-ip/info.php

You should see a PHP information page confirming the setup.

Step 5: Install PHP 8.4 FPM for Nginx

PHP-FPM (FastCGI Process Manager) is required to process PHP scripts for users of the Nginx web server. Follow these steps to install and configure PHP-FPM.

Install PHP-FPM

Run the following command to install PHP-FPM:

sudo apt install -y php8.4-fpm

Verify PHP-FPM Status

Check the status of the PHP-FPM service to ensure it is running:

sudo systemctl status php8.4-fpm

Expected Output:

● php8.4-fpm.service - The PHP 8.4 FastCGI Process Manager     Loaded: loaded (/usr/lib/systemd/system/php8.4-fpm.service; enabled; preset: enabled)     Active: active (running)       Docs: man:php-fpm8.4(8)    Process: 11741 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/8.4/fpm/pool.d/www.conf 84 (code=exited, status=0/SUCCESS)   Main PID: 11737 (php-fpm8.4)     Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0.00req/sec"      Tasks: 3 (limit: 2218)     Memory: 8.0M (peak: 9.0M)        CPU: 116ms     CGroup: /system.slice/php8.4-fpm.service             ├─11737 "php-fpm: master process (/etc/php/8.4/fpm/php-fpm.conf)"             ├─11739 "php-fpm: pool www"             └─11740 "php-fpm: pool www"

Configure Nginx to Use PHP-FPM

Edit the default Nginx site configuration file:

sudo nano /etc/nginx/sites-available/default

Locate the server block and add the following configuration:

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php8.4-fpm.sock;
}

Test and Restart Nginx

Validate the Nginx configuration:

sudo nginx -t

If the syntax check is successful, restart Nginx to apply the changes:

sudo systemctl restart nginx

Verify the Installation

Create a test PHP file similar to the Apache setup:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Open a browser and navigate to:

http://your-server-ip/info.php

You should see the PHP information page.

Step 6: Install PHP Extensions

Extensions enhance the functionality of PHP. Installing them is straightforward.

Install Specific Extensions

Use the following syntax to install extensions:

sudo apt install php8.4-[extension]

Example: Install Common Extensions

Install commonly used extensions with this command:

sudo apt install -y php8.4-mysql php8.4-imap php8.4-ldap php8.4-xml php8.4-curl php8.4-mbstring php8.4-zip

Verify Installed Extensions

List all installed PHP modules:

php8.4 -m

Expected Output (Partial):

[PHP Modules]imapjsonldaplibxmlmbstringmysqlimysqlndopensslpdo_mysql...

Step 7: Run PHP 8.4 Alongside Other Versions

If your system has multiple PHP versions, you can manage them using the update-alternatives command.

List Available PHP Versions

Run the following command to list installed PHP versions:

sudo update-alternatives --config php

Sample Output:

There are 2 choices for the alternative php (providing /usr/bin/php).

  Selection    Path             Priority   Status
------------------------------------------------------------
* 0            /usr/bin/php.default   100       auto mode
  1            /usr/bin/php.default   100       manual mode
  2            /usr/bin/php8.3        83        manual mode
  3            /usr/bin/php8.4        84        manual mode

Set PHP 8.4 as Default

To set PHP 8.4 as the default version:

sudo update-alternatives --set php /usr/bin/php8.4

You may also like:

Conclusion

In this tutorial, we have provided a detailed guide on how to install PHP 8.4 on Ubuntu 24.04. Starting from updating your system to adding the required repositories, installing PHP, configuring it for both Apache and Nginx, installing extensions, and managing multiple PHP versions, this guide is designed to make the process seamless for both beginners and advanced users.

By following these steps, you can set up PHP 8.4 to develop and host dynamic web applications efficiently. Whether you’re upgrading from an older PHP version or setting up PHP for the first time, this guide equips you with the necessary commands and configurations to get started.

For further learning and troubleshooting, we highly recommend consulting the official PHP documentation. Additionally, the Linux and Ubuntu communities are excellent resources for seeking help and sharing experiences.

If you have any questions or encounter issues during the installation, feel free to leave a comment below or reach out to community forums for additional support. Happy coding!


Topics:#Linux#php
RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Linux & Servers•

How to Install PDO Extension in PHP

PHP Data Objects (PDO) is one of the most important extensions in PHP for working with databases in a secure, consistent, and modern way. If you are building dynamic websites, APIs, CMS platforms, or enterprise applications, PDO is not opti...

RR
Rajesh Rai
Read More
Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout