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: