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.
php binary is available in default PATH variable for Ubuntu and other Linux variance if installed using the default package manager. You might need to use full path for the binary if it's manually installed or using other methods such as XAMPP for Windows.
$ 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
$ php -i | grep "PHP Version" PHP Version => 7.4.3 PHP Version => 7.4.3
<?php echo PHP_VERSION_ID; //Sample output: 70403 ?>
<?php echo phpversion(); //Sample output: 7.4.3 ?>
<?php phpinfo(); ?>
$ apt show php Package: php Version: 2:7.4+75 Priority: optional Section: php Source: php-defaults (75) Origin: Ubuntu Maintainer: Ubuntu Developers <firstname.lastname@example.org> Original-Maintainer: Debian PHP Maintainers <email@example.com> Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 13.3 kB Depends: php7.4 Download-Size: 2,712 B APT-Sources: http://jp.archive.ubuntu.com/ubuntu focal/main amd64 Packages Description: server-side, HTML-embedded scripting language (default) PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML. . This package is a dependency package, which depends on latest stable PHP version (currently 7.4).
Package manager query comand for different operating systems and distributions:
|homebrew||$ brew list --versions php|
|Debian, Ubuntu||$ apt show php|
|CentOS, RedHat, Fedora||$ dnf info httpd|
Comment anonymously. Login not required.