How to Update PHP on your site or server.

If you want to keep your website running smooth and secure, it is a good idea to keep your PHP version as up to date as possible. There are many beneficial reasons why one would want to update the PHP version on their sites, such as staying up to date on the latest security and bug fixes and being able to keep up with the latest updates from your favorite themes and plugins.

Also, the lifetime of older PHP versions is running out. Active support for version 5.6 ended at the beginning of 2017. Security support will only be provided until the end of 2018. This means that versions of PHP 5.6 or higher should be used as they are the only versions currently receiving security updates. So if you plan on updating PHP it should be to a version 5.6 or greater.

Before You Update PHP...

While that does sound awesome it's not always smooth sailing when updating PHP. There are a few things to keep in mind before updating the PHP version on your site or server:

Not all themes and plugins may be up to date with the newest or latest versions of PHP. You will want to check the documentation for the plugins and themes you are using to make sure they will support the PHP version you are updating to. If you are unsure of whether a certain theme or plugin will work with newer versions of PHP please contact the author of the plugin or theme.

There are also plugins that will check the code on your site to see if they are compatible with later versions of PHP.

PHP Compatibility Checker This plugin will lint theme and plugin code inside your WordPress file system and give you back a report of compatibility issues for you to fix. Compatibility issues are categorized into errors and warnings and will list the file and line number of the offending code, as well as the info about why that line of code is incompatible with the chosen version of PHP.

Error Log Monitor This plugin will log PHP errors in your WordPress dashboard so you can view if you have any incoming incompatibility errors when using a more up to date PHP version. You will always want to watch your site's error logs after updating PHP that way you can see if it is causing any errors that were not on your site previously.

Note: These are third-party plugins and are not associated with iThemes in any way; install them on your site at your own risk.

Besides themes and plugins, if you have any other software on your server that is utilizing PHP code then it is a good idea to check the documentation or contact the author of the software to make sure the code is compatible with the PHP version you are updating to.

Before updating your PHP version it is always a great idea to BACKUP your website!!

Time to Update PHP!

As stated previously in the article, it is best to make sure your site is running on a version 5.6 or higher as any version before that is no longer receiving security updates. When attempting to figure out which PHP version to switch or update to, it is a good idea to check the WordPress requirements codex article here: https://wordpress.org/about/requirements/ This article lets you know the PHP version WordPress recommends that you use.

Shared Hosting:

If you are on a shared hosting platform, more than likely, your host has a select few versions of PHP for you to choose from. Often, these can be switched from the cpanel or custom control panel that your host has provided. Just select version 5.6 or higher and save the setting. If there is no way to change this from your host's control panel, please contact them directly and ask them to update your PHP to a version 5.6+ or higher.

If they refuse to update your PHP to a version 5.6+ or move your site to a server that has a more update to date PHP version, it is time to switch hosts.

VPS or Dedicated Server:

Please note that the following is informational and if you are unsure if you should be running these commands then please refer to your host and their relevant documentation.

If you are using ubuntu 14.04 or greater, you can use the following commands:

This will add the repository for PHP versions 5.6 and 7.0

sudo apt-add-repository ppa:ondrej/php

To install and update to 5.6, use the command:

sudo apt-get install php5.6

Then, for 7.0, use the command:

sudo apt-get install php7.0

If you are using MYSQL, you need to run the following command for PHP 7:

sudo apt-get install php7.0-mysql

Now all that is left is to restart your server for the changes to take effect.