PHP is a most popular server scripting language used for creating dynamic and interactive Web pages. Recently PHP 8 has been released officially. This tutorial explains how to install PHP 8 on CentOS 8 system.
PHP 8.0 is the latest major release and includes performance improvements, and lots of new features such as named arguments, JIT compiler, union types, match expression, and more. We’ll use REMI repository to install PHP 8.
Prerequisites
You must logged in with root or user with sudo privileges.
Install PHP 8 on CentOS 8
Perform the following steps to install PHP 8
on CentOS system.
Step 1 – Update System
Use the following command to update your CentOS 8 / RHEL 8 system.
sudo dnf update
sudo dnf upgrade
Once the updates applied, you can reboot your system using below command. It’s an optional to reboot.
sudo reboot
Step 2 – Enable EPEL & Remi Repository
By default, CentOS 8 package repositories doesn’t includes PHP 8. So, we have to enable EPEL and remi repositories. Run following commands to enable:
sudo dnf install -y epel-release
sudo dnf install -y http://rpms.remirepo.net/enterprise/remi-release-8.rpm
sudo dnf install -y dnf-utils
Step 3 – Install PHP 8
Run the following commands to reset PHP module and install PHP 8 from remi-8.0
module.
sudo dnf module reset php
sudo dnf module install -y php:remi-8.0
Step 4 – Verify Installation
You can verify the installation using --version
command:
php -v
PHP 8.0.0 (cli) (built: Nov 24 2020 17:04:03) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
with Zend OPcache v8.0.0, Copyright (c), by Zend Technologies
By default, Nginx doesn’t have a built-in support for processing PHP files. So we need to use PHP FPM service to handle the PHP files.
sudo dnf install -y php-fpm
You must start and enable its services once the php-fpm
package is installed. Run following command:
sudo systemctl enable php-fpm --now
To verify the status of php-fpm
service, run:
systemctl status php-fpm
Installing PHP Extensions
You can install PHP extensions as per requirements. You can easily install extensions using dnf package manager in following form:
sudo dnf install -y php-[extension]
For example, to install curl and mbstring
extensions, you would run the following command:
sudo dnf install -y php-{curl,mbstring}
You must restart the Apache or PHP FPM service after installing extensions.
Conclusion
I hope you successfully learned how to install PHP 8 on CentOS 8 / RHEL 8 system.
If you have any questions or feedback, please leave a comment below.