Home » CentOS » How to Install PHP 7 on CentOS 8 Linux Operating System

How to Install PHP 7 on CentOS 8 Linux Operating System

Last updated Sep 2, 2021

The CentOS 8 Operating system comes with PHP version 7.0, and you can install like any other application package using the apt package manager. Today, in this article, we will learn to install PHP 7.2 on CentOS 8 machine.

Prerequisites

To perform practical stuff of this tutorial, make sure you have CentOS 8 installed machine and user to log in on system with sudo privileges.

Install PHP 7.2 on CentOS 8

To install PHP 7.2 on CentOS 8 operating system follow below steps:

Step 1: Update package list

To install any package on CentOS system need to update the repository’s package list by using the following command:

$ sudo yum update

Step 2: Enable REMI repository

There are multiple repository available to provide PHP, but we use REMI repository as it is good to provide various application with latest distribution.

The REMI repository is depends on EPEL repository, so we use below command to enable both EPEL and REMI repository.

$ sudo yum install epel-release yum-utils
$ sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

You may get the window to import GPG key for repository, just press ‘Y’ and hit Enter button.

Step 3: Install PHP 7.2

After enabling the REMI repository, again update the package list using the following command:

$ sudo yum update

Now, enable the PHP 7.2 Remi repository using following command:

$ sudo yum-config-manager --enable remi-php72

After enable the repository you can start installation of PHP 7.2 using following command:

$ sudo yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlnd

Step 4: Verify Installation

You can verify the php installation by checking the version of PHP by using “php –v” command, as shown below:

$ php –v
  • Facebook
  • Twitter
  • reddit
  • LinkedIn

Configuring Apache to run PHP

If you are running the PHP application on the web browser, you have to configure it with web server Apache or Nginx.

In this section, we will see how to configure an Apache web server with PHP 7.2. To configure PHP with apache, you have to install PHP and apache library for PHP by using below command:

$ sudo yum install php7.2 libapache2-mod-php

After installation of PHP and apache library restart the apache service:

$ sudo systemctl restart httpd

Configure Nginx to run PHP

Nginx doesn’t have built-in support for PHP like an apache web server. So, to use Nginx with PHP need to install another application PHP FPM, which will handle PHP files and operation.

You can install PHP and PHP FPM package by using the following command:

$ sudo apt install php7.2 php7.2-fpm

Once the PHP FPM package installed in your system, you can handle it like any other application.

You can enable, start, or stop services. You can check the status of PHP FPM by using below command:

$ systemctl status php7.2-fpm
  • Facebook
  • Twitter
  • reddit
  • LinkedIn

To use PHP FPM with Nginx web server, need to edit the server block and add the following code so the Nginx can process php files using PHP FPM:

server {
    # . . . other code
    location ~ .php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    }
}

After configuring the server block, need to restart Nginx service by using below command:

$ sudo systemctl restart nginx

Install PHP extensions

PHP has numbers of functionalities, which can have enabled by using several numbers of PHP extensions.

To enable those features, need to install PHP extension by using the following command syntax:

$ sudo yum install php-[extname]

For example, if you want to install GD, IMAP PHP extension, you can install by using the following command:

$ sudo yum install php7.2-imap php7.2-gd

After installation of PHP extension, you need to restart webserver apache/nginx and PHP FPM services.

Testing PHP

You can test PHP by using a web server, and you can identify PHP is running by a web server.

To verify PHP with the webserver, create a new file with name info.php inside the web server’s root directory “/var/www/html” with the following code:

<?php
phpinfo();

Save the file and open the file into a web browser like below:

http://server-ip/info.php

The function phpinfo will print the information about PHP configuration as shown as below image:

  • Facebook
  • Twitter
  • reddit
  • LinkedIn

Conclusion

Now, you have learned “How to install PHP on CentOS 8 Operating System?” and also learn to configure PHP with a web server like Apache or Nginx.

Related Posts

How to Install MongoDB on CentOS 8 Linux

How to Install MongoDB on CentOS 8 Linux

MongoDB is an open-source and free NoSQL document based database system. Nowadays, it is prevalent as most application developers are using MongoDB, which can handle big data. As a MongoDB is a NoSQL database, It stores data in JSON-like documents where fields can...

How to Install OpenCV on CentOS 8 Linux

How to Install OpenCV on CentOS 8 Linux

OpenCV (Open Source Computer Vision Library) is an open-source computer vision and machine learning software library. OpenCV was built to provide a common infrastructure for computer vision applications and to accelerate the use of machine perception in commercial...

How to install and use FFmpeg on CentOS 8 Linux Operating System

How to install and use FFmpeg on CentOS 8 Linux Operating System

The FFmpeg is the most potent and useful command-line tool on Linux system for multimedia files transcoding. You can use FFmpeg to convert multimedia files between various video and audio formats and resize videos. It has multiple audio and video libraries such as...

How to Install VirtualBox on CentOS 8 Linux

How to Install VirtualBox on CentOS 8 Linux

VirtualBox is an Open Source tool, known as a cross-platform virtualization application or software. It used to run multiple operating systems or virtual machines simultaneously on a single hardware. In this VirtualBox installation tutorial, we will explain the...

Follow Us

Our Communities

More on CentOS

The Ultimate Managed Hosting Platform
Load WordPress Sites in as fast as 37ms!

0 Comments

0 Comments

Submit a Comment

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

16 − 16 =

Shares