How to Update PHP from PHP 7.x to PHP 7.4 on CentOS 7?

Here is the way how I upgrade the PHP from PHP 7.3 to PHP 7.4 on CentOS. The first and most important thing is to backup snapshot of your server before updating PHP

Currently, PHP had updated to Current Stable PHP 8.1.13, however, there are many WordPress website-run environments are still keep using PHP 7.3.

In fact, the FAQ geek website is running on PHP 7.3 just a moment ago. Here is the way how I upgrade the PHP from PHP 7.3 to PHP 7.4 on CentOS.

Update PHP from PHP 7.x to PHP 7.4 on CentOS 7

1. The first and most important thing is to backup snapshot of your server before updating PHP.

2. Then you should do is do any core OS updates and package updates.

yum update -y

You will see your php version just like:

PHP 7.3.11 (cli) (built: Nov 25 2019 23:58:23) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies

3. Check which version of PHP you are currently running. php -v

To print a list of all the PHP packages you have installed. You will need to replace all these packages in PHP 7.4. You should copy this list to a file so you can refer to it if you need to. Make a note of the version of PHP here (7x or 7-x).

rpm -qa | grep php

rpm -qa | grep php > php_rpm.txt

How to List Compiled PHP Modules on Linux?

Here is another way to use the Linux command to display the modules installed on the Linux system.

The command php -m will show a list of all “compiled” PHP modules.

# php -m
[PHP Modules]
bcmath
Core
ctype
curl
date
dom
filter
ftp
gd
gettext
hash
iconv
intl
json
libxml
mbstring
...
sysvsem
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
xsl
zip
zlib

[Zend Modules]

4. Remove PHP core and all the installed PHP packages.

yum remove "php*" -y

5. Install the updated remi repository if it is not already installed.

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

6. Check out a list of all available remi packages (not-required)

yum repolist remi-safe

7. Disable PHP 7.x and enable PHP 7.4 (Replace x with sub-version of your previously installed version noted above in step 3) and install any extra packages you want / need.

yum --disablerepo=remi-php7x --enablerepo=remi-php74 install php php-pdo php-fpm php-gd php-mbstring php-mysql php-curl php-mcrypt php-json -y

8. Check the updated PHP version.

php -v

9. Restart Apache to use the newly installed PHP 7.4

 systemctl restart httpd 

Or restart Nginx to use the PHP 7.4

/usr/local/nginx/sbin/nginx -s reload

Reference: https://stackoverflow.com/questions/62870093

Download PHP install package: www.php.net