How to Check PHP Version
The PHP programming language is available in many different versions and configurations. To know what PHP utilities you have available and what extensions are enabled, it is important to be able to verify which version of PHP is running.
In this guide, we will go through ways in which we can check what version of PHP is running on your server.
Check Using phpinfo()
The easiest way to find out all information about the version of PHP your web application is actually using is by calling the PHP utility
Create a file called
info.php and place it in your webroot (where
index.php is, which is usually in a folder called
Once you have done this load
yourdomain.com/info.php in a browser.
A page will load that provides information about the active PHP version for that web app. It tells you everything from what packages are loaded to the maximum upload size allowed, just to name a couple of examples.
Check PHP Version with the Command-line
It is also possible to check what version of PHP is running from the command-line. Firstly let's check where PHP is installed on the system using the
To get the version information type in
php followed by
PHP 7.2.20-2+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Jul 25 2019 11:42:36) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.20-2+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
Note - the version of PHP that appears in the command-line may not be the one used by
www-data and therefore not your website. It is important to be aware of this if there are multiple PHP installations on your server.
Print Version using phpversion()
If you just need to know what version of PHP is running on your website for certain and no other information, use the
Like the example with
phpinfo() create a new PHP file in your webroot and use the following code:
<?php echo phpversion();
You know how to check what version of PHP is running in three different ways. Personally I always use the
phpinfo() utility because it tells you everything and you can be left in no doubt that it is the actual PHP version being used by
www-data for your web application.