Check PHP version

We can check our PHP version in 2 major ways; via a PHP function and via the command line. The version of PHP which we are using is sometimes important as some scripts rely on functions that are only available in some versions. It is a good idea then to check the version of PHP before using these scripts.

Check PHP version using a script

PHP offers a useful function called phpversion which provides us with the current version of the PHP interpreter.

To get the current PHP version from a script, we can use the code below or edit it as necessary:

<?php
 
echo 'Your current PHP version is ' . phpversion();
 
?>

The output of this function may be something similar to:

Your current PHP version is 5.0.4

You can use this function in your scripts to add additional compatibility checks especially when the script may run on many different platforms.

Check PHP version using the command line in Ubuntu or other version of Linux

We can also check the version of PHP we have by executing a command in the terminal.

Open a command line and execute the following:

php -v

You will get some output similar to the following:

PHP 5.0.2-1ubuntu4.9 with Suhosin-Patch (cli) (built: Jan 25 2009 10:03:41)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies

From that you can tell that you are running PHP version 5.0.2.

Those are the 2 major ways provided to check the current PHP version. We hope this PHP tutorial was useful to you.

Thank Tutorial Arena for This Tutorial.
Show your appreciation with a +1...