Install PHP 7.4, 7.3, 7.2, 7.1 on CentOS 7 & CentOS 8 - Step by Step Process ?

PHP is a popular server-side scripting language and widely used for creating interactive and dynamic web pages. PHP 8.0.6 is the latest stable version of PHP which was released on 6 May 2021.

Here at LinuxAPT, as part of our Server Management Services, We regularly help our Customers to perform related PHP queries.

In this context, we shall look into how to use EPEL and Remi repository to install PHP 7 on CentOS 7 server.


How to Install PHP 7 on CentOS ?

Before proceeding with the installation steps and procedure, you need to ensure that the user have sudo privileges enabled to be able to install packages.


1. Configure Yum Repository

To begin, you have to install and enable EPEL and Remi yum repository on your CentOS 7 server. Run the below commands to install and enable EPEL and Remi yum repository:

$ sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
$ sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

Now we are going to install yum-utils. It is a collection of useful programs for managing yum repositories and packages. It has tools that improve yum's default features.

$ sudo yum install yum-utils

Next, we will use yum-config-manager program which is included in yum-utils. We will use it to enable Remi repository as the default repository for installing different PHP versions.

Now you can install the stable version of PHP on your server.

Run the following commands to install PHP 7 on CentOS 7 server.

First choose specific php version of your choice and enable appropriate Remi repository for install PHP 7 as below:

For PHP 7.4
$ yum --enablerepo=remi-php74 install php
For PHP 7.3
$ sudo yum-config-manager --enable remi-php73
For PHP 7.2
$ sudo yum-config-manager --enable remi-php72
For PHP 7.1
$ sudo yum-config-manager --enable remi-php71

After that, install PHP 7 with additional necessary modules which can extend the core functionality. Run below command:

$ sudo yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo

Now, PHP is installed with specific version. 

Afterwards, you can check the installed PHP version.


2. Install PHP Modules

You may also need to install additional PHP modules based on your application requirements. Below command will install some more useful PHP modules:

## Install PHP 7.4 ##
$  yum --enablerepo=remi-php74 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
## Install PHP 7.3 ##
$ yum --enablerepo=remi-php73 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
## Install PHP 7.2 ##
$ yum --enablerepo=remi-php72 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
## Install PHP 7.1 ##
$ yum --enablerepo=remi-php71 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt

You can run the following command to search other available PHP modules under configured yum repositories. 

Below example command search for all modules for PHP 7.4.

$ yum --enablerepo=remi-php74 search php | grep php74
Output:
* remi-php74: mirror.innosol.asia
php74.x86_64 : Package that installs PHP 7.4
php74-php.x86_64 : PHP scripting language for creating dynamic web sites
php74-php-bcmath.x86_64 : A module for PHP applications for using the bcmath
php74-php-brotli.x86_64 : Brotli Extension for PHP
php74-php-cli.x86_64 : Command-line interface for PHP
php74-php-common.x86_64 : Common files for PHP
php74-php-componere.x86_64 : Composing PHP classes at runtime
php74-php-dba.x86_64 : A database abstraction layer module for PHP applications
php74-php-dbg.x86_64 : The interactive PHP debugger
php74-php-devel.x86_64 : Files needed for building PHP extensions
php74-php-embedded.x86_64 : PHP library for embedding in applications
php74-php-enchant.x86_64 : Enchant spelling extension for PHP applications
...
...


3. Verify PHP Installation

You can check installed PHP version using command line by type:

$ sudo php -v

It will show you output as below:

PHP 7.3.1 (cli) (built: Jan  8 2019 13:55:51) ( NTS )
 Copyright (c) 1997-2018 The PHP Group
 Zend Engine v3.3.1, Copyright (c) 1998-2018 Zend Technologies
     with Zend OPcache v7.3.1, Copyright (c) 1999-2018, by Zend Technologies

Next, you can test your system to know if it is configured properly for PHP, create a very basic PHP script called info.php file.

So create this file at web root of server.

In CentOS 7 directory is located at /var/www/html/ so create file here by executing this command :

$ sudo nano /var/www/html/info.php

Add the following PHP code inside the file:

<?php
phpinfo();
?>

At last, Save and close file. Now visit this page in web browser using your server's public IP address as following:

http://YOUR_SERVER_IP/info.php

This will display the current PHP Version running on the system as well as the extensions.


[Need urgent assistance in fixing Server PHP errors ? We can help you. ]

This article covers how to install specific version of PHP 7 on CentOS 7 Linux server. PHP is a programming language often used to automate server tasks. It is part of the LAMP (Linux, Apache, MySQL, PHP) stack, which is a bundle of software used for running internet servers and services. PHP handles dynamic content, database requests, and processing and displaying data.


To Verify PHP Version:

You can Check which version of PHP you are running with the command:

$ php –v


To Install PHP with Apache on CentOS:

1. Start by installing the yum-utils package by entering the following command in a terminal window:

$ sudo yum install yum-utils –y

2. Then, enable the epel-release repository by entering the following:

$ sudo yum install epel-release –y

3. Finally, add the following software repositories that contain the PHP packages:

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

4. For PHP 7.3, you can enable PHP 7.3. Install the release with the following commands:

$ sudo yum-config-manager ––enable remi–php73
$ sudo yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysql –y

Related Posts