Set your site to use newest PHP version
How to Update PHP Version
In this guide you'll learn how to make your site use the latest PHP version. PHP is a server-side scripting language, most often used in web development. The WordPress core and most WordPress plugins and themes are written in PHP.
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. 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.
Why change to the newest PHP version?
PHP updates usually include several security and performance related improvements. It is therefore recommended to change to the newest PHP version as soon as it's possible. Learn more on the WordPress Support site.
A major change in PHP versions occurred in late 2018, when official security support for the widely used 5.6 ended. Seravo's latest blog posts on the subject can be found on our website with the keyword "PHP". We always blog about all the most relevant changes!
How to change the PHP version?
Note: We recommend that you take a backup of the site before updating the PHP version. This will allow the site to be restored to as recent a version as possible in case something goes wrong during the update and other changes made to the site during the same day are not lost. If you need to restore your site from a backup, you can contact Seravo's customer support at help@seravo.com . Restoring the site from a backup is a part of our routine customer support, free of charge.
WordPress dashboard (wp-admin)
By logging to the admin panel of your WordPress site and going to the Upkeep page under the Tools menu, you get to change the PHP version of your site to your liking. The same tool also shows the current PHP version used.
Command line
You can also use the command wp-check-php-version
over SSH to display the current PHP version in use. If you use an older PHP version, the command will return a warning of the versions security has ended.
With a recent PHP version in use, command output will look like this:
Checking for PHP backends... Found PHP mode definition: php8.0 in '/data/wordpress/nginx/php.conf' Using php8.0 php8.0
With an older PHP in use, command output will look like this:
Checking for PHP backends... Using default PHP mode (php5) !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! WARNING: PHP 7.0 is deprecated, security support has ended 3rd December 2018! ! ! ! ! See <https://seravo.com/docs/configuration/php7-hhvm/> for more details. ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! php5
PHP version should be defined in /data/wordpress/nginx directory, where you should create a php.conf file and set in this file the following: “set $mode php8.0;”. The version number in the command must be changed to the desired one. 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. Learn more on our documentation for developers.
With the command below, you can choose to do all of the above at once:
echo "set \$mode php8.0;" | tee /data/wordpress/nginx/php.conf && wp-restart-nginx
After the change, it's good to check the error logs of the site to make sure the change didn’t trigger any errors. Log file can be found from under the /data/log directory. You can also check this directly from the WordPress admin panel.
How to check if plugins are compatible with the newest PHP?
WordPress dashboard (wp-admin)
Compatibility checking is done with the same tool you use to change the PHP version. Log in to the WordPress admin and open the Upkeep section under the Tools menu, where you will find the Seravo-plugin tool.
Command line
Site's plugins compatibility with the newest PHP can be checked with wp-php-compatibility-check
, that’ll reveal PHP code incompatibilities and give you some details, why the plugin in question isn’t compatible.
The test results are logged in the file /data/log/wp-php-compatibility.log
and inside the log file you will find warnings like the one below for some of the plugins you are using:
FILE: /data/wordpress/htdocs/wp-content/plugins/stackable-ultimate-gutenberg-blocks/freemius/includes/class-freemius.php ---------------------------------------------------------------------------------------------------------------------------------- FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES ---------------------------------------------------------------------------------------------------------------------------------- 18305 | WARNING | Since PHP 7.0, functions inspecting arguments, like func_get_args(), no longer report the original value as | | passed to a parameter, but will instead provide the current value. The parameter "$tag" was used, and possibly | | changed (by reference), on line 18303. 18462 | WARNING | Since PHP 7.0, functions inspecting arguments, like func_get_args(), no longer report the original value as | | passed to a parameter, but will instead provide the current value. The parameter "$tag" was used, and possibly | | changed (by reference), on line 18460. ----------------------------------------------------------------------------------------------------------------------------------
You can use the wp-php-compatibility-check
command to check the compatibility of an individual theme with the latest version of PHP:
$ wp-php-compatibility-check /data/wordpress/htdocs/wp-content/themes/twentytwenty .............................. 30 / 30 (100%) Time: 529ms; Memory: 14MB Scan complete. Results are stored in the logfile /data/log/wp-php-compatibility.log
The command can also be used to check the compatibility of a specific plugin:
$ wp-php-compatibility-check /data/wordpress/htdocs/wp-content/plugins/autodescription ............................................................ 60 / 114 (53%) ...................................................... 114 / 114 (100%) Time: 3.86 secs; Memory: 18MB Scan complete. Results are stored in the logfile /data/log/wp-php-compatibility.log
Additionally, you can view compatibility for a specific version of PHP by adding the version number to the end of the command:
$ wp-php-compatibility-check /data/wordpress/htdocs/wp-content/themes/twentytwenty 7.4 .............................. 30 / 30 (100%) Time: 530ms; Memory: 14MB Scan complete. Results are stored in the logfile /data/log/wp-php-compatibility.log