Recently WordPress had seen PHP7.2 as an unsafe version and popped up a dialog in the admin dashboard, so I found the solutions for both version of CentOS 7/8 to update PHP version to 7.4.
Before any operation, don’t forget to backup your website.
How to install PHP 7.x on CentOS 7/8 for NGINX?
0. You may want to update yum modules (Optional)
$ sudo yum update
For CentOS7
1. Search for PHP version, run
$ yum repolist all | grep php
If you don’t have remi-php74
install and enable the Remi’s repo for PHP 7.4 by
$ sudo yum install yum-utils http://rpms.remirepo.net/enterprise/remi-release-7.rpm
2. Enable the PHP7.4 version
$ yum-config-manager --enable remi-php74
If the php version is successfully set, details of loaded plugins will list in the output.
3. Update PHP
After the PHP version set, it is time to upgrade PHP 7.x on your CentOS 7 server by typing the following command:
$ sudo yum update php
After confirming the target version, press y
to let the process start.
For CentOS8
1. Search for PHP version, run
$ sudo yum module list php
Last metadata expiration check: 0:51:12 ago on Mon May 24 16:11:14 2021.
CentOS Linux 8 - AppStream
Name Stream Profiles Summary
php 7.2 [d][e] common [d], devel, minimal PHP scripting language
php 7.3 common [d], devel, minimal PHP scripting language
php 7.4 common [d], devel, minimal PHP scripting language
Remi's Modular repository for Enterprise Linux 8 - x86_64
Name Stream Profiles Summary
php remi-7.2 common [d], devel, minimal PHP scripting language
php remi-7.3 common [d], devel, minimal PHP scripting language
php remi-7.4 common [d], devel, minimal PHP scripting language
php remi-8.0 common [d], devel, minimal PHP scripting language
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
If you don’t have php:7.4
or php:remi-7.4
module in the list, install and enable the Remi’s repo for PHP 7.4 by
$ sudo yum install yum-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm
2. Enable the PHP7.4 version
Before enable the version you want, you need to reset the version in advanced.
$ sudo yum module reset php
$ sudo yum module enable php:7.4
## verify it php set to 7.4 ##
$ sudo yum module list php
In the above example, php:7.4
is enabled, of course you can choose php:remi-7.4
either.
3. Installation
After the PHP version set, it is time to install PHP 7.x on your CentOS 8 server by typing the following command:
$ sudo yum install php php-fpm
If you do not want Apache (httpd) installed as dependencies, run:
$ sudo yum install php-fpm php-common php-cli
After Installation…
4. Check and Start Service
$ php -v
$ sudo systemctl enable php-fpm.service
$ sudo systemctl start php-fpm.service
$ sudo systemctl status php-fpm.service
References
- How To Install PHP 7.4 on CentOS 7
- 在CentOS 7系统上安装PHP 7.4版本的方法
- How To Install PHP 7.4 on CentOS 8 / RHEL 8
- How to Install PHP 7.x on CentOS 8 For Nginx