Newer PHP versions come with more features and improvements while deprecating some obsolete features. Old PHP codes might not work with more recent PHP versions and vice versa. It is, therefore, essential to use the correct PHP version for your code.
You can check the PHP version on your system by running the php command from the command line. There are also some PHP functions that you can use in your code to get the PHP version during runtime.
Steps to check the installed PHP version:
- Run php -v from the command line.
$ php -v
PHP 7.4.3 (cli) (built: May 26 2020 12:24:22) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies - Run php -i from the command line.
$ php -i | grep "PHP Version"
PHP Version => 7.4.3
PHP Version => 7.4.3
3. Print PHP_VERSION_ID from PHP script.
<?php
echo PHP_VERSION_ID;
//Sample output: 70403
?>
4. Print phpversion() output from PHP script.
<?php
echo phpversion();
//Sample output: 7.4.3
?>
5. View from phpinfo() output.
<?php
phpinfo();
?>