I had a CentOS 7 system running WordPress and received the warning: WordPress has detected that your site is running on an insecure version of PHP. The system was running PHP 5.6 which is end of life, so here are the steps I used to upgrade to the latest version recommended by WordPress at the time of this posting (PHP 7.3).
- If not already installed:
sudo yum install epel-release
- Add the IUS repository that maintains updated PHP packages.
More information can be found at the following site including these commands:
https://ius.ioFor CentOS 7yum install \ https://repo.ius.io/ius-release-el7.rpm \ https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
For CentOS 6
yum install \ https://repo.ius.io/ius-release-el6.rpm \ https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
Note: if you get Error: Nothing to do when using the above commends it means you may already have the repository installed and is safe to ignore.
- Since we are using IUS repository we will use the replace plugin
More information about this plugin for reference:
https://github.com/iuscommunity/yum-plugin-replaceyum install yum-plugin-replace
- The next step depends on your specific configuration. If you are on a stock CentOS 7 install you can use
yum replace --replace-with php73-common php
Note: if you receive Error: Package ‘php’ is not installed then you are not on a stock install and you must replace php with the specific version you have installed. Inspect the output of the command:
yum list installed | grep php
Then perform the yum replace command using the package name you have installed. For example:
yum replace --replace-with php73-common php56u
Note: if you receive WARNING: Unable to resolve all providers it probably means identical replacements for all php extensions could not be found which is typical. Press y to continue.
- This server was running Apache so it needs to be restarted for the new PHP to take effect:
apachectl restart
- At this point the WordPress installation was broken: There has been a critical error on your website. Setting WordPress into debug mode revealed the following Fatal error: Uncaught Error: Call to undefined function json_encode() … /wp-includes/functions.php:3820 To resolve it, install the json extension:
yum install php73-json
- Then restart Apache again
apachectl restart
- Now WordPress should be functional again and no longer reporting an out of date version of PHP.