Upgrade to PHP 7 on CentOS 7 (or CentOS 6)

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).

  1. If not already installed:
    sudo yum install epel-release
  2. 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 7

    yum 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.

  3. 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-replace

    yum install yum-plugin-replace
  4.  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.

  5. This server was running Apache so it needs to be restarted for the new PHP to take effect:
    apachectl restart
  6. 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
  7. Then restart Apache again
    apachectl restart
  8. Now WordPress should be functional again and no longer reporting an out of date version of PHP.
This entry was posted in Uncategorized. Bookmark the permalink.