How To Install PHP 8.4 on Rocky Linux 9 / AlmaLinux 9

PHP is a recursive acronym that stands for Hypertext Processor. It is a popular general-purpose scripting language used in web development and can be embedded in HTML. It is a fast, unique, flexible, and pragmatic language that powers from simple blog sites to popular websites. PHP is mainly used in server-side scripting where you use s a PHP parser ( CGI or server module) to collect form data, generate dynamic page content, or send and receive cookies. But PHP can do much more like command line scripting that allows you to run a PHP script without any server or browser and write desktop applications with a graphical interface including cross-platform applications.

PHP can be used in all major operating systems including Windows, macOS, and Linux. It supports web servers to work either as a module or a CGI processor, this includes servers like Apache, IIS, Lighttpd, and Nginx. PHP includes different abilities like outputting images, PDF files, and even Flash movies and outputting any text, such as XHTML and any other XML file. PHP has useful text-processing features like Perl-compatible regular expressions that parse and access XML documents. It also supports a wide range of databases while writing to the database is simple with the use of specific extensions like MySQL, using an abstraction layer like PDO, or Open Database Connection standard via the ODBC extension.

The latest version release is 8.4 which is a security release and contains a lot of improvements and bug fixes. This guide will show you how to install PHP 8.4 on Rocky Linux 9 / AlmaLinux 9.

Install PHP 8.4 on Rocky Linux 9 / AlmaLinux 9

Enable EPEL and REMI repositories in Rocky Linux 9 and AlmaLinux 9.

sudo dnf config-manager --set-enabled crb
sudo dnf install epel-release -y
sudo dnf install http://rpms.remirepo.net/enterprise/remi-release-9.rpm
sudo dnf update -y

Once done, list the available PHP streams. You can see the remi-8.4 php module.

$ sudo dnf module list php
AlmaLinux 9 - AppStream
Name      Stream       Profiles                       Summary                   
php       8.1          common [d], devel, minimal     PHP scripting language 
php       8.2          common [d], devel, minimal     PHP scripting language   

Remi's Modular repository for Enterprise Linux 9 - x86_64
Name      Stream       Profiles                       Summary                   
php       remi-7.4     common [d], devel, minimal     PHP scripting language    
php       remi-8.0     common [d], devel, minimal     PHP scripting language    
php       remi-8.1     common [d], devel, minimal     PHP scripting language    
php       remi-8.2     common [d], devel, minimal     PHP scripting language
php       remi-8.3     common [d], devel, minimal     PHP scripting language  
php       remi-8.4     common [d], devel, minimal     PHP scripting language      

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

Enable the module before installing PHP 8.4.

sudo dnf -y install yum-utils
sudo dnf module enable php:remi-8.4 -y

Using PHP 8.4 with Apache Web server

Install the Apache web server.

sudo dnf install httpd httpd-tools -y

Start and enable the service.

sudo systemctl start httpd
sudo systemctl enable httpd

To install PHP for Apache run the following command.

sudo dnf install php php-cli php-common php-fpm
sudo systemctl enable --now php-fpm

Edit the PHP configuration file using the following command.

sudo vim /var/www/html/info.php

Add the following code and save the file.

<?php
phpinfo();
?>

Using PHP 8.4 with Nginx Web server

Install Nginx with the following command.

sudo dnf install nginx vim -y

Start and enable the service to start on boot.

sudo systemctl start nginx
sudo systemctl enable nginx

Install PHP on the Nginx web server by running the following command.

sudo dnf install php php-cli php-common php-fpm

It is recommended to prevent Nginx from passing requests to the PHP-FPM backend if the file does not exist. Edit the following file.

sudo vi /etc/php.ini

Locate cgi.fix_pathinfo= and modify it as follows then save the file:

cgi.fix_pathinfo=0

Enable Nginx to use PHP-fpm to serve PHP files.

sudo vim /etc/nginx/nginx.conf

Edit the configuration file. Add the following below the location block and save the file.

location / {
    root   html;
    index  index.php index.html index.htm;
}

location ~* \.php$ {
    fastcgi_index   index.php;
    fastcgi_pass    127.0.0.1:9000;
    include         fastcgi_params;
    fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
}

Text for the file syntax.

$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Start and enable PHP-FPM service:

sudo systemctl enable --now php-fpm

Reload Nginx to apply changes.

sudo systemctl reload nginx

Create a test file.

sudo vim /usr/share/nginx/html/info.php

Add the following lines and save the file.

<?php
phpinfo();
?>

Verify PHP installation

If you have Firewalld service running open http port.

sudo firewall-cmd --add-service={http,https} --permanent
sudo firewall-cmd --reload

Check for the PHP version after the installation.

$ php -v
PHP 8.4.2 (cli) (built: Dec 17 2024 15:31:31) (NTS gcc x86_64)
Copyright (c) The PHP Group
Built by Remi's RPM repository <https://rpms.remirepo.net/> #StandWithUkraine
Zend Engine v4.4.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.2, Copyright (c), by Zend Technologies

Go to the Web browser at http://localhost/info.php to get the following screen.

Check out our Web Hosting services!

Wrap Up

PHP is a popular general-purpose programming language that is used in web development to produce dynamic web content. It contains a lot of features that make it a fast and flexible scripting language including the main one that it can be embedded into HTML. Others include using PHP from the command line, support of cookies and sessions, handling file uploads, using remote files, and enabling HTTP authentication.

Check out more articles:

Your IT Journey Starts Here!

Ready to level up your IT skills? Our new eLearning platform is coming soon to help you master the latest technologies.

Be the first to know when we launch! Join our waitlist now.

Join our Linux and open source community. Subscribe to our newsletter for tips, tricks, and collaboration opportunities!

Recent Post

Leave a Comment

Your email address will not be published. Required fields are marked *

Related Post

Greetings. Python 2.7, Python 3.5, and Python 3.6 reached EOL requiring Python developers to upgrade to new releases { Python […]

We previously installed Asterisk LTS 18 on Rocky Linux 9 and we saw that it can only be administered from […]

In this blog post we will install Asterisk 18 with FreePBX on Rocky Linux / AlmaLinux 9. Asterisk is a […]

Let's Connect

Unleash the full potential of your business with CloudSpinx. Our expert solutions specialists are standing by to answer your questions and tailor a plan that perfectly aligns with your unique needs.
You will get a response from our solutions specialist within 12 hours
We understand emergencies can be stressful. For immediate assistance, chat with us now

Contact CloudSpinx today!

Download CloudSpinx Profile

Discover the full spectrum of our expertise and services by downloading our detailed Company Profile. Simply enter your first name, last name, and email address.