How To Check Your PHP Version

There may come a time where you need to know which PHP version your web server is running. In this guide I will be showing you multiple ways to check which PHP version your Linux server is running.

Find PHP Version Using The PHP Command

The quickest and easiest way to find out which PHP version you are running is by using the PHP command along with the –version argument. Here is the command below as-well as an example output.

php --version
PHP 7.0.22-0ubuntu0.16.04.1 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.22-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies

You can also use the PHP command to run PHP code directly, in the following example we will be checking the phpinfo() function to see which version of PHP we are running. The first example will only display which version of PHP you are running, the second will display which version the extensions and libraries are.

php <<< "<?php phpinfo(); ?>" | grep "php extension version"
php extension version => 7.0.22-0ubuntu0.16.04.1

php <<< "<?php phpinfo(); ?>" | grep version
version => 1.0.5
GMP version => 6.1.0
iconv library version => 2.23
json version => 1.4.0
libmbfl version => 1.3.2
oniguruma version => 5.9.6
mbstring extension makes use of "streamable kanji code filter and converter", which is distributed under the GNU Lesser General Public License version 2.1.
Multibyte regex (oniguruma) version => 5.9.6
libmemcached version => 1.0.18
Client API library version => mysqlnd 5.0.12-dev - 20150407 - $Id: b5c5906d452ec590732a93b051f3827e02749b83 $
Client API version => mysqlnd 5.0.12-dev - 20150407 - $Id: b5c5906d452ec590732a93b051f3827e02749b83 $
Phar EXT version => 2.0.2
Phar API version => 1.1.1
core library version => xmlrpc-epi v. 0.54
php extension version => 7.0.22-0ubuntu0.16.04.1
Zip version => 1.13.5
Libzip version => 1.0.1

Find PHP Version By Checking PHP Package Version

If the above method fails then you can go directly to your package manager to find out which version of PHP you are running. To do this we will list all installed packages and then use the grep command to search for PHP. Here are two examples based on the 2 most common distributions.

For Ubuntu, Debian, and all derivatives please use the following command.

dpkg --list | grep php

For Red Hat, CentOS, Fedora, and any of their derivatives, please use this command instead.

yum list installed | grep php

Find PHP Version By Using An Actual PHP File

Last but not least, you can check by using an actual PHP file. Keep in mind that your web directory may be located in a different directory than the one below. This is assuming you have a default setup and are not using shared hosting, if you are then you will need to change the directory accordingly. So lets get this started by creating the file with the following command.

echo '<?php phpinfo(); ?>' > /var/www/html/phpinfo.php

After you have created this file, you should be able to use a browser and navigate to the file we just created (for example You should be able to see your PHP version on this page, as-well as plenty of other useful information if you are currently configuring PHP settings.

I hope this guide helped you, please don’t forget to like, comment, or share. Thanks for the support!

Leave a Reply

Protected with IP Blacklist CloudIP Blacklist Cloud