How to Easily Check the PHP Version

Last updated on by Digamber
PHP is a popular server-side programming language. It was introduced back in the year 1995 and created by Rasmus Lerdorf. It is an exclusively useful programming language to create an excellent web application. PHP means Hypertext Preprocessor, and a web server processes it.

There are some use cases where we require to find out which PHP versions is working on a web server.

If you plan to build a new web application and might want to update your PHP application, you may need to check the particular PHP version before getting started with the installation.

In this tutorial, i am going to share with you a few useful methods through which you can easily check which PHP version your server is working on.

PHP has been around since a very long time, since its inception it has brought us lots of version updates in the below chart you can see the PHP version history.

PHP Version History

Check PHP Version from Command Line or Terminal

This method requires SSH access to the webserver, and you can find out the PHP version using the following command.

You can append either -v or --version with php keyword.

php --version

# or 

php -v
# output

PHP 7.3.11 (cli) (built: Feb 29 2020 02:50:36) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies

The above commands will give you the same output on your terminal screen, so currently, we have installed PHP 7.3.11 version.

What if you are a web server is using exquisite versions of PHP. In this case, you can run the `php` command from the terminal shell, but it will display only the default PHP CLI version. It might be the different version of PHP is being used by the web application.

Find Out PHP version with phpinfo()

The easiest method is to check the PHP version is the phpinfo() method. This function displays heaps of information about the PHP server, such as PDO, calendar, installed extensions, environment, compilation options, PHP version, web server information, and many more.

Create a file by the name of domain.com/check-php-version.php, and the place the following code in this file:

<?php

    phpinfo();

?>

Then type the following URL on the browser’s address bar and press enter.

http://domain.com/check-php-version.php

Then the full PHP configuration will be displayed on your browser’s screen along with the PHP version.

Check the PHP Version

If you specifically want to check the PHP version and don’t want to expose the full php details, then you can use the following php method.

<?php

   echo 'Current PHP version is: ' . phpversion();

?>

Summary

Finding out the PHP server details is not that difficult task. In this tutorial, I have shared with your the simplest methods to verify the PHP versions your server is using.

I hope you would love this tutorial and share with others as well.