In this article, we will have explained the necessary steps to install and configure PHP on CentOS 8. Before continuing with this tutorial, make sure you are logged in as a user with sudo
privileges. All the commands in this tutorial should be run as a non-root user.
PHP is one of the most used server-side programming languages. Many popular CMS and frameworks such as WordPress, Laravel, and many more are built in PHP.
Install PHP on CentOS
Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.
sudo yum install epel-release sudo yum update
Step 2. Enable the Remi repository.
Enable the Remi repository by running the following command:
sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm
Once the installation is complete, run the command to get a list of all available PHP versions:
sudo dnf module list php
Our Result:
Last metadata expiration check: 0:08:16 ago on Sat 21 Oct 2019 08:46:52 PM UTC. CentOS-8 - AppStream Name Stream Profiles Summary php 7.2 [d][e] common [d], devel, minimal PHP scripting language Remi's Modular repository for Enterprise Linux 8 - x86_64 Name Stream Profiles Summary php remi-7.2 common [d], devel, minimal PHP scripting language php remi-7.3 common [d], devel, minimal PHP scripting language php remi-7.4 common [d], devel, minimal PHP scripting language Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
The default PHP module is set to PHP 7.2. The command below will install a number of PHP extensions as well required for different integrations:
sudo dnf module reset php sudo dnf module enable php:remi-7.4
Then, install PHP and some of the most common PHP modules:
sudo dnf install php php-opcache php-gd php-curl php-mysqlnd
After the installation is complete, check your PHP version using the following command:
$ php -v PHP 7.4.0RC3 (cli) (built: Oct 21 2019 08:46:34) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0-dev, Copyright (c) Zend Technologies
Congratulation, you have learned how to install and configure PHP on CentOS 8. If you have any questions, please leave a comment below.