Set your site to use newest PHP version

In this guide you learn, how you can transfer your site to using the newest PHP version, that is supported in Seravo. PHP is a server-side scripting language, that is most often used in web development. Most WordPress plugins are written in PHP.

Why change to the newest PHP version?

The most important thing, why you should migrate to PHP 7.2 is that PHP versions 5.6 and 7.0 security support is ending. The support for the version 5.6 is ending on 2018-12-31 and 7.0 support is ending on 2018-12-3. PHP 7.2 is preferred for of both security and speed optimizations. PHP 7.2 comes with better PHP security and at the same time some older security techniques were dropped out. More infomation on the WordPress Support site.

Command `wp-check-php-version` shows the current PHP version in use. If you use an older PHP version, the command will return a warning of the versions security support ending soon.

With newest PHP in use, command output will look like this:

Checking for PHP backends...
Found PHP mode definition: php7.2 in '/data/wordpress/nginx/php.conf'
php7.2

With an older PHP in use, command output will look like this:

Checking for PHP backends...
Using default PHP mode (php5)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! WARNING: PHP 5.6 is deprecated, security support will end 31th December 2018! !
!                                                                               !
! See <https://seravo.com/docs/configuration/php7-hhvm/> for more details.      !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
php5

How to check if plugin is compatible with the newest PHP?

Plugins compatibility with PHP 7.2 can be checked with `wp-php-compatibility-check`, that’ll reveal incompatibilities with the newest PHP and give you some details, why the plugin in question isn’t compatible.

If your plugins are compatible, the command output should look like this:

............................................................  60 / 158 (38%)
............................................................ 120 / 158 (76%)
......................................                       158 / 158 (100%)

Time: 3.39 secs; Memory: 62.01Mb

Scan complete. Results are stored in the logfile /data/log/wp-php-compatibility.log

If there is one or more plugins, that are incompatible with PHP 7.2, output will something like the following:

............................................................  60 / 159 (38%)
............................................................ 120 / 159 (75%)
..................................E....                      159 / 159 (100%)


FILE:
wp-content/plugins/welcome-email-editor/sb_welcome_email_editor.php
--------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 4 WARNINGS AFFECTING 5 LINES
--------------------------------------------------------------------------------------------------------------
 91 | WARNING | Function create_function() is deprecated since PHP 7.2; Use an anonymous function instead
213 | WARNING | Function create_function() is deprecated since PHP 7.2; Use an anonymous function instead
229 | WARNING | Function create_function() is deprecated since PHP 7.2; Use an anonymous function instead
329 | WARNING | Function create_function() is deprecated since PHP 7.2; Use an anonymous function instead
912 | ERROR   | Extension 'mysql_' is deprecated since PHP 5.5 and removed since PHP 7.0; Use mysqli instead
--------------------------------------------------------------------------------------------------------------

Time: 3.37 secs; Memory: 62.01Mb

Scan complete. Results are stored in the logfile /data/log/wp-php-compatibility.log

With the command `wp-php-compatibility-check`, you can also check if some specific plugin or a theme is compatible with newest version of PHP.

Example #1:

wp-php-compatibility-check /data/wordpress/htdocs/wordpress/wp-content/themes/twentyseventeen

With the command `wp-php-compatibility-check`, you can also check the compatibility of a specific PHP version with some specific plugin or a theme:

Example #1:

wp-php-compatibility-check /data/wordpress/htdocs/wordpress/wp-content/themes/twentyseventeen 7.2

Example #2:

wp-php-compatibility-check “” 7.2


NOTE! If wp-php-compatibility-check returns errors, you can’t do a version update before the errors have been fixed. Seravo’s plans do not include fixing a plugin or theme to work with the newest PHP version. Seravo only updates the plugin or theme to the newest version and it is generally on the plugin developers responsibility to maintain the plugin. But if you can’t fix the errors yourself, you can contact our customer support for recommendations on digital agencies or freelancers whom you could buy the necessary work to upgrade or fix the plugins you need.

How to change the PHP version?

PHP version can be defined in /data/wordpress/nginx directory, where you should create a php.conf file and set in this file the following: “set $mode php7.2;”. After that you must restart the Nginx by running wp-restart-nginx, because the nginx needs to restart to the new PHP version configuration can take place. Before you do these changes, however, you should take backup of your site.

echo "set \$mode php7.2;" | tee /data/wordpress/nginx/php.conf && wp-restart-nginx

Next check the PHP error log (php-error.log), that the change didn’t trigger any errors. Log file can be found from under the /data/log directory. You can open the error log by: cat /data/log/php-error.log or better yet use wp-watch-logs for a live view of the logs, while you browse the site.

More information about the logs: https://help.seravo.com/en/docs/47-logs-available-for-the-site

PHP error log can also be found from the admin panel of your WordPress site when you are logged in. From the admin panel you can find the logs from under the “Tools” → “Logs” menus. In there you can view all the logs available on the environment.


More information on the version change

5.6.x -> 7.0.x

7.0.x -> 7.1.x

7.1.x -> 7.2.x

Did this solve your problem?