Trying to install Latest PHP version on CentOS 7

Posted October 13, 2019 25.5k views

I’ve been trying to install the latest PHP version on my CentOS 7 droplet but every install keeps missing some key extensions.

If I try to add them afterwards, there are some dependency failures which really bugs me. I’ve removed and installed PHP from 5.4 to 7.3 about a dozen times already. Can someone provide me with some proper stepts to do so.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hi @Remdore,

So I ran into the same problem a day ago. Even if you install PHP 7.2 with yum something without any preparation always doesn’t work right away.

So, to install ANY PHP version you wish, you can follow these steps bellow just change the php version to your needs

Install EPEL yum repository on your system

yum install epel-release

Install Remi repository

rpm -Uvh

Now onto the proper installation

Your system is prepared for the PHP installation from yum repositories. Use one of the following commands to install PHP 7.3 or PHP 7.2 or PHP 7.1 on your system based on your requirements

## Install PHP 7.3 
yum --enablerepo=remi-php73 install php

## Install PHP 7.2 
yum --enablerepo=remi-php72 install php

## Install PHP 7.1 
yum --enablerepo=remi-php71 install php

Now running the following command to check current active PHP version on my system.

php -v
PHP 7.2.23 (cli) (built: Sep 25 2019 07:38:48) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies 

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.

### For PHP 7.3
yum --enablerepo=remi-php73 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt

### For PHP 7.2
yum --enablerepo=remi-php72 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt

### For PHP 7.1
yum --enablerepo=remi-php71 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt

Any other extension you would like to install, you can do it like

### For PHP 7.2
yum --enablerepo=remi-php72 install php-extensioname

Kind regards,

  • Thank you soo much! Everything worked off without a problem.

    Thank you for the fast answer as well!

    I do have one other question if possible. How can I search through all the available php extension and their versions? Is there like a page somewhere or?

    • Glad to be of help!

      Well, I don’t know about a page but there is a way to actually search those from yum :

      yum --enablerepo=remi-php73 search php | grep php73

      I won’t post the whole output as it will be overwhelmingly large but here is part of the output

      php73.x86_64 : Package that installs PHP 7.3
      php73-php.x86_64 : PHP scripting language for creating dynamic web sites
      php73-php-bcmath.x86_64 : A module for PHP applications for using the bcmath
      php73-php-brotli.x86_64 : Brotli Extension for PHP
      php73-php-cli.x86_64 : Command-line interface for PHP
      php73-php-common.x86_64 : Common files for PHP
      php73-php-componere.x86_64 : Composing PHP classes at runtime
      php73-php-dba.x86_64 : A database abstraction layer module for PHP applications
      php73-php-dbg.x86_64 : The interactive PHP debugger

      Now, there is no way to check the exact version until you don’t try to install it. Here is an example with litespeed

       yum install php73-php-litespeed.x86_64
       Package                                                  Arch                                        Version                                                 Repository                                      Size
       php73-php-litespeed                                      x86_64                                      7.3.10-1.el7.remi                                       remi-safe                                      1.6 M
      Installing for dependencies:
       php73-php-common                                         x86_64                                      7.3.10-1.el7.remi                                       remi-safe                                      641 k
       php73-php-json                                           x86_64                                      7.3.10-1.el7.remi                                       remi-safe                                       69 k
       php73-runtime                                            x86_64                                      2.0-1.el7.remi                                          remi-safe                                      1.1 M
      Transaction Summary
      Install  1 Package (+3 Dependent packages)

      As you can see it actually displays the Version as well.

      Kind regards,