Get the PHP Version at Command Line (3 examples)

To find the PHP version you can combine php and grep.

Get the major/minor version only
php -v | grep -Po '(?<=PHP )([0-9].[0-9])'


Get full version number only
php -v | grep -Po '(?<=PHP )([0-9.]+)'


Get the full version
php -v

PHP 7.2.10-0ubuntu0.18.04.1 (cli) (built: Sep 13 2018 13:45:02) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.10-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies

Leave a Reply

Your email address will not be published. Required fields are marked *