How to Install PHP 7.4, 7.3, 7.2 on CentOS 7 and RHEL 7 Server

As we know that PHP is the most important part of LAMP applications (WordPress, Joomla, Drupal & Media wiki etc). Now a days most of these applications require PHP 7 for their installation and configuration. Main advantage of PHP 7.x is that it will load your web application faster and will consume less server’s resources like CPU and RAM.

By default, PHP 5.4 is available in CentOS 7 and RHEL 7 yum repositories.  In this article we will demonstrate how to install latest version of PHP on CentOS 7 and RHEL 7 Servers.


Installation Steps of PHP 7.1, 7.2, 7.3 and 7.4 on CentOS 7 Server

1) Install yum-utils and enable EPEL repository

Login to your server and use the below yum command to install yum-utils & enable epel repository

[root@linuxtechi ~]# yum install epel-release yum-utils -y

2) Download and Install remirepo using yum command

[root@linuxtechi ~]# yum install

3)  Based on your requirement, configure the PHP 7.x repository

To configure PHP 7.1 repository, use below command,

[root@linuxtechi ~]# yum-config-manager --enable remi-php71

To configure PHP 7.2 repository, use below command,

[root@linuxtechi ~]# yum-config-manager --enable remi-php72

To configure PHP 7.3 repository, use below command

[root@linuxtechi ~]# yum-config-manager --enable remi-php73

To configure PHP 7.4 repository, use below command

[root@linuxtechi ~]# yum-config-manager --enable remi-php74

4) Install PHP 7.4 along with dependencies.

In this tutorial, I will install latest version of PHP 7.4 along with its modules, Run beneath yum command

[root@linuxtechi ~]# yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysql -y

Note: To search all PHP modules use  below command:

[root@linuxtechi ~]# yum search php | more

5) Verify the PHP version

Once PHP and its dependencies are installed in step4), use below command to verify the installed PHP version,

[root@linuxtechi ~]# php -v
PHP 7.4.4 (cli) (built: Mar 17 2020 10:40:21) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.4, Copyright (c), by Zend Technologies
[root@linuxtechi ~]#

Installation Steps of PHP 7.x on RHEL 7 Server

1) Enable EPEL, RHEL 7 Server Optional repository and Install remirepo rpm

Login to your RHEL 7 Server and run the beneath commands one after the another to enable EPEL repository, install remirepo and enable RHEL 7 Server optional repository

[root@linuxtechi ~]# rpm -Uvh
[root@linuxtechi ~]# wget
[root@linuxtechi ~]# rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm
[root@linuxtechi ~]# subscription-manager repos --enable=rhel-7-server-optional-rpms

2) Configure PHP 7.x repo

[root@linuxtechi ~]# yum install yum-utils
[root@linuxtechi ~]# yum-config-manager --enable remi-php74

3) Install PHP 7.4 and its dependencies

[root@linuxtechi ~]# yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysql -y

4) Verify PHP Version

[root@linuxtechi ~]# php -v

PHP 7 Test Page Verification

I am assuming Apache web Server is installed on your system, start its service using below systemctl command

[root@linuxtechi ~]# systemctl start httpd
[root@linuxtechi ~]#

Now create a info.php file under /var/www/html with following contents,

[root@linuxtechi ~]# cd /var/www/html/
[root@linuxtechi html]# vi info.php

Open the web browser and type the ip of your server followed by info.php,



This confirms that you have successfully installed PHP 7.4 on your system. That’s all from this article, please do share your feedback and comments.

Also Read: How to Install PHP 7.4 on CentOS 8 / RHEL 8

14 thoughts on “How to Install PHP 7.4, 7.3, 7.2 on CentOS 7 and RHEL 7 Server”

  1. I prefer using Debian over CentOS. While I have used both, I like Debian because it has a good support and vast community. Also installing PHP 7 on a Debian based server is easy for me because the hosting for PHP (‘’) website I am using provides managed servers with Debian and stack already installed in one click.

  2. Error
    Package php-7.2.13-2.el7.remi.x86_64 is obsoleted by mod-php-5.6-apache2-zend-server-5.6.38-152.x86_64 which is already installed

  3. Trying to install php74 from remi repo but it does not install the apache module and no amount of yum search find any apache module in the remi repos. Any help would be greatly appreciated.

  4. You can’t follow these instructions exactly.

    What will happen is that it will re-install PHP 5.6, which was just removed.

    You have to “yum install php74 php74-php-cli php74-php-mysqld … ” etc.

    • It seems when I did that, it created a “/bin/php74” executable instead of “/bin/php”, which was easily resolved with a “ln” command.

    • I believe part of the problem I encountered was that I had already followed similar instructions to install PHP 5.6. The default for CentOS 7 is PHP 5.4. So in order further upgrade to PHP 7.4 you must disable PHP 5.6. So at Step 2 to “configure PHP 7.x repo” you might also need to add “yum-config-manager –disable remi-php56” (or whatever version had been configured previously). Once that’s done, re-install 7.4, and all is well.

  5. I had php5.6w and rh-php7.3
    This process replaced php5.6w and now I can not run php in CGI wrapper , it doesnt execute, it downloads the php file.
    When I switch to mod_php mode, new php7.4 remi works.
    I need to run in CGI wrapper how can I undo this process?
    yum history undo # is enough or do I need to yum-config-manager –disable remi-php74 first?
    Any help will be highly appreciated.

  6. Hi,

    I installed mediawiki using your following tutorial:

    it is going good, but when I open my browser, it shows the mediawiki page with a warning that mediawiki 1.34 does not work with PHP version 5.4.16. I must have at least PHP 7.2.9. So, I am trying to upgrade it. I followed your this tutorial for that. Till step 3, it works fine, but when I use yum to install it, there I get an error.
    I always use the following yum command to install anything
    “yum –disablerepo=\* –enablerepo=c7-media install php”

    “c7-media is to link it to baseurl where I mounted my centOS.iso file that contains all packages.” And it contains PHP version 5.4.16.

    Now to install this new version of PHP, how to RUN yum command, because “yum install php” does not work for me. it gives me error “unable to find the valid baseurl”. Can you please help me out in this.

    OR can you please tell how to get the .tar file for old version of mediawiki (1.24 etc).
    Thank you for your help


Leave a Comment