How To Install PHP 8 on Rocky Linux 8
In this tutorial, we will show you how to install PHP 8 on Rocky Linux 8. For those of you who didn’t know, PHP is a popular general-purpose scripting language that is especially suited to web development. The PHP version 8 has been released with new features and optimization including null safe operator, Just in Time Compiler (JIT), error handling, match expression, etc.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of the PHP 8 on Rocky Linux. 8.
Prerequisites
- A server running one of the following operating systems: Rocky Linux 8.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install PHP 8 on Rocky Linux 8
Step 1. The first step is to update your system to the latest version of the package list. To do so, run the following commands:
sudo dnf check-update sudo dnf update sudo dnf install dnf-utils
Step 2. Install and enable EPEL and REMI Repository.
Now we add the REMI repository and the EPEL (Extra Packages for Enterprise Linux) repository by executing the following command:
sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
Step 3. Installing PHP on Rocky Linux 8.
By default, PHP is available on Rocky Linux 8 base repository. Now run the following command below to reset the default PHP module and enable PHP 8 module using the following command:
sudo dnf module reset php sudo dnf module enable php:remi-8.1
Note: In case you want to enable some other module version of PHP, then just change the version number in the above-given command.
Finally, install PHP packages using the command below:
sudo dnf install php
Now, you can verify the installation:
php -v
Output:
[root@idroot.us ~]# php -v PHP 8.1.0RC6 (cli) (built: Feb 14 2022 15:26:22) ( NTS gcc x86_64 ) Copyright (c) The PHP Group Zend Engine v4.0.6, Copyright (c) Zend Technologies with Zend OPcache v8.1.0RC6, Copyright (c), by Zend Technologies
Step 4. Installing PHP Extensions.
To install any particular extension, use the following syntax:
sudo dnf install php-extension-name
For example, install the PHP-fpm module for Nginx:
sudo dnf install php-fpm
After the installation is complete, start the PHP-fpm service and enable it to run automatically at every boot using the following command:
sudo systemctl enable php-fpm sudo systemctl start php-fpm sudo systemctl status php-fpm
Congratulations! You have successfully installed PHP. Thanks for using this tutorial for installing the PHP 8 on your Rocky Linux 8 system. For additional help or useful information, we recommend you check the official PHP website.