Almost eight out of ten websites use PHP (according to W3Techs) and most are WordPress sites – yet 64% are using old versions no longer officially supported. Considering the latest versions are faster and safer from hacking, it makes sense for every webmaster to keep on top of updates. At the time of writing, the latest version of PHP is 7.4.8, and version 8.0.0 is in alpha.

The catch with upgrading is that new conflicts can arise, usually from code that has only been tested with earlier versions. Therefore, there are two good reasons for knowing your current PHP version:

  • To check that you are up-to-date
  • To confirm that your code or a library/plugin is compatible.

Because many websites depend critically on particular libraries or plugins, the PHP open-source development team provide security updates and support for several recent versions (7.2.x, 7.3.x and 7.4.x) so even if you defer a full version update, you should still be applying the latest iteration of your version (for example updating 7.2.30 to 7.2.32).

Finding your version number is usually simple, but if you host several domains on the same server, remember that each may be using different plugins and different versions of PHP.

Method 1: using your admin panel

cPanel, ISPmanager, Plesk, and most other admin panels record the PHP version in use. There is also a WordPress plugin called “Display PHP Version” that posts it to the WordPress dashboard.

Reading the version from your admin panel is the most obvious way to locate it quickly, but there is a known issue with some panels not updating the information they display after updates have been applied. This is unusual but be aware of it.

In cPanel you will find the PHP version in cPanel > Software > Select PHP Version. The version is displayed just above the PHP extensions.

In Plesk, it is more complicated. Find “Hosting Services” in the left column. Then under “Domains” click the domain you are checking for. On the following screen click “Hosting Settings” and scroll down to “Web scripting & statistics” which contains the PHP version in use.

Method 2: using phpinfo()

This is a more reliable method because it checks the website directly. It also provides you with more information. You create a simple PHP file called (for example) phpinfo.php which contains the following lines:

<?php
phpinfo();
?>

You can either create the file in the server directory, or you can create it offline and upload it to the root of the website via FTP (or SFTP). To do it the first way, use your admin panel to navigate to the File Manager. If you are using cPanel navigate to the “public_html” directory (in ISPmanager you could use the “www” directory instead). You can then create and edit your new file.

To see the output, navigate to the file with a browser, for example, http://yourdomain.com/phpinfo.php. You will see the version and a lot more information. Delete the file when you’ve finished because it is poor security to advertise your PHP version.

Method 3: using phpversion()

You can use this function in much the same way as above, but it only reports the default PHP version of the server, not (necessarily) the website:

<?php
phpversion();
?>

Method 4: using the command line

If you have SSH access to the server, you can type “php” with the “-v” option set (or use the verbose form “—version”).

$ php -v

This method only tells you the default PHP CLI server version, which can differ from the version used for hosting your site, so it’s advisable to use one of the alternative methods where possible.

If after checking your PHP version you decide that you need to update it, it’s advisable to perform a backup first so that you can roll back if you encounter an insoluble problem such as a conflict with a critical plugin you cannot immediately replace. If you are using WordPress, there is a plugin you can install called “PHP Compatibility Checker“. This is pretty good at warning you in advance if the update you are contemplating is likely to cause an issue with any of the plugin versions you already have installed. You can then look to see if there is a later version of your plugin or a better alternative.

 

Leave a reply

 

Your email address will not be published.