Summary
In this post, I will introduce how to update PHP for WordPress.
Conclusion
As usual, I present the following snippets first.
sudo yum remove php-common mod_php php-cli
sudo yum install epel-release
sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum install yum-utils
sudo yum-config-manager --enable remi-php72
sudo yum install php php-mysql –y
sudo systemctl restart httpd
Details
For faster speed and more secure, I want to update the PHP from the default version to the latest one. I did some research and finally, succeed in updating. It is necessary to record it for future maintenance.
Before the update, please read the official guide from WordPress first and back up your site. Use this checker to check the compatibilities of all your plugins.
Now, we start updating.
1. Remove the Old PHP
# php --version
PHP 5.4.16 (cli) (built: Mar 7 2018 13:34:47)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
We hate slow and unsecure ones and want to remove them.
sudo yum remove php-common mod_php php-cli
After which, we get
# php --version
bash: /bin/php: No such file or directory
2. Install a Newer PHP
Turn on EPEL repo on a CentOS sever.
sudo yum install epel-release
Turn on remi repo too.
sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
Enable remi repo, run:
sudo yum-config-manager --enable remi-php72
Update softwares.
sudo yum install php php-mysql –y
It will find the php 7.2.
==================================================================================
Package Arch Version Repository Size
==================================================================================
Installing:
php x86_64 7.2.16-1.el7.remi remi-php72 3.2 M
php-mysqlnd x86_64 7.2.16-1.el7.remi remi-php72 233 k
Installing for dependencies:
php-cli x86_64 7.2.16-1.el7.remi remi-php72 4.8 M
php-common x86_64 7.2.16-1.el7.remi remi-php72 1.1 M
php-json x86_64 7.2.16-1.el7.remi remi-php72 64 k
php-pdo x86_64 7.2.16-1.el7.remi remi-php72 126 k
Now check the version of php again.
# php --version
PHP 7.2.16 (cli) (built: Mar 5 2019 13:10:50) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.16, Copyright (c) 1999-2018, by Zend Technologies
3. Restart Apache
Remember to restart Apache service.
systemctl restart httpd