Hi all,

I host 2 WordPress sites using Apache(httpd) on my droplet and am getting the nagging message to upgrade my version of PHP. I’ve found some tutorials and article on installing PHP, but nothing regarding upgrading from one version of PHP to another, and nothing particularly for CentOS 8. Can anyone give me some pointers or offer any advice on how to safely upgrade from PHP 7.2 to 7.4?

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
2 answers

Hi @jplafata,

In order to upgrade from one PHP version to another just need to install it. There is no actual upgrade process like upgrading from Ubuntu 16 to 18. You just install your new PHP version and make that the default one.

Anyway, let’s see how to install PHP 7.4

To get started, you need to add EPEL & Remi repository from where you will be able to install PHP 7.4 on CentOS 8 Linux.

dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

Next once you have the EPEL repository, run:

dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm

Upon successful addition of EPEL and Remi repositories, execute the command below to get a list of available PHP module streams.

 dnf module list php

You should see an output of PHP version. The one we care about is remi-7.4, the latest PHP stream, To enable the module stream run the following :

dnf module enable php:remi-7.4

Once the PHP remi-7.4 module has been enabled, you can then proceed and install PHP

dnf install php php-cli php-common

Regards,
KFSys

  • Thanks @KFSys! This worked. The only additional step I had to take was run dnf module reset php prior to dnf module enable php:remi-7.4 to disable the old version.

  • I did all this in trying to upgrade 7.3 to 8.0, but php -v still shows 7.3. The DNF stuff shows 8, it seems, because when I do dnf module reset php it shows me the 8.0 to be reset.

    When I run the dns install php...., it ends with this:

    Running transaction check
    Transaction check succeeded.
    Running transaction test
    The downloaded packages were saved in cache until the next successful transaction.
    You can remove cached packages by executing 'dnf clean packages'.
    Error: Transaction check error:
      file /usr/lib64/libwebp.so.7 from install of libwebp-1.0.0-1.el8.x86_64 conflicts with file from package libwebp7-1.0.3-1.el7.remi.x86_64
      file /usr/lib64/libwebpdecoder.so.3 from install of libwebp-1.0.0-1.el8.x86_64 conflicts with file from package libwebp7-1.0.3-1.el7.remi.x86_64
      file /usr/lib64/libwebpdemux.so.2 from install of libwebp-1.0.0-1.el8.x86_64 conflicts with file from package libwebp7-1.0.3-1.el7.remi.x86_64
      file /usr/lib64/libwebpmux.so.3 from install of libwebp-1.0.0-1.el8.x86_64 conflicts with file from package libwebp7-1.0.3-1.el7.remi.x86_64
      file /usr/lib64/libip4tc.so.0.1.0 from install of iptables-libs-1.8.4-15.el8.x86_64 conflicts with file from package iptables-1.4.21-33.el7.x86_64
      file /usr/lib64/libip6tc.so.0.1.0 from install of iptables-libs-1.8.4-15.el8.x86_64 conflicts with file from package iptables-1.4.21-33.el7.x86_64
      file /usr/lib64/libiptc.so.0.0.0 from install of iptables-libs-1.8.4-15.el8.x86_64 conflicts with file from package iptables-1.4.21-33.el7.x86_64
      file /usr/lib64/libgd.so.3 from install of gd-2.2.5-7.el8.x86_64 conflicts with file from package gd-last-2.3.0-1.el7.remi.x86_64
      file /usr/share/man/man1/vim.1.gz from install of vim-common-2:8.0.1763-15.el8.x86_64 conflicts with file from package vim-minimal-2:7.4.629-6.el7.x86_64
      file /usr/share/pixmaps/poweredby.png from install of centos-logos-httpd-80.5-2.el8.noarch conflicts with file from package centos-logos-70.0.6-3.el7.centos.noarch
    
    

    Could this be related to having php73-xxx in the past and now I have php-xxx? What do I need to do so that new PHP-FPM etc are used and PHP is actually upgraded? Thanks!

    • Hi @NearlyNormal,

      In your case, most probably you just have both PHP 7.3 and 8.0 installed and the default PHP version is 7.3. If you do a

      ls -lah /usr/bin/php*
      

      What do you see?

      • It’s possible I have both 7.4 and 8.0 installed.

        # ls -lah /usr/bin/php*
        -rwxr-xr-x. 1 root root 6.1M Nov 25 01:59 /usr/bin/php
        -rwxr-xr-x. 1 root root 6.1M Nov 25 01:59 /usr/bin/php-cgi
        -rwxr-xr-x. 1 root root 4.7K Nov 25 01:59 /usr/bin/phpize
        

        And the version:

        # php -v
        PHP 8.0.0 (cli) (built: Nov 24 2020 17:04:03) ( NTS gcc x86_64 )
        Copyright (c) The PHP Group
        Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
            with Zend OPcache v8.0.0, Copyright (c), by Zend Technologies
        

        How do I make my 7.4 the default for now? PHP 8 is too new and way to much of a headache. Thanks!

        • Hi @NearlyNormal.

          The thing is I can’t find 7.4 in your ls -lah command. Usually the way to go is

          Command Line:-
          
          sudo update-alternatives --set php /usr/bin/php7.4
          sudo update-alternatives --set phar /usr/bin/phar7.4
          

          If you are using Apache it’s

          sudo a2enmod php7.4
          sudo service apache2 restart
          

This was super helpful to upgrade a CENTOS 8 machine from PHP 7.2 to 7.4. I turned it into a quick script to automate it and to make sure you install all of the PHP 7.2 modules you had previously.

Enjoy

#!/usr/bin/bash
#This script upgrades CENTOS 8 from PHP 7.2 to 7.4
#-----------------------------------------

if [ `whoami` != "root" ];
then
echo "Sorry, gotta be root!"
exit 0
fi

echo "This script will upgrade PHP 7.2 to 7.4 on Centos 8"
echo ""
echo "Press CTRL-C to stop, or any key to continue"
read ans

if [[ `cat /etc/centos-release | grep 'CentOS Linux release 8.'` ]];
then
echo "You are on Centos 8, proceeding."
else
echo "Not on Centos 8. Sorry, exiting."
exit 1
fi

echo "These are your current PHP modules installed. Saving to /tmp/php-7.2.modules.txt"
echo ""
rpm -qa | grep php | tee -a /tmp/php-7.2.modules.txt
echo ""

pkgs=`rpm -qa --queryformat "[%{NAME}\n]" | grep php | sort`

dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
dnf module list php
dnf module reset php
dnf module enable php:remi-7.4

dnf install $pkgs

echo "Upgrade complete."