If you have access to the command line or terminal, then you can check your PHP version by running the php -v
or php --version
command.
Here’s an example of the output:
$ php -v
PHP 8.1.5 (cli) (built: Apr 16 2022 00:03:58) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.5, Copyright (c) Zend Technologies
with Zend OPcache v8.1.5, Copyright (c), by Zend Technologies
You can see that the command shows the PHP version as PHP 8.1.5
.
But sometimes you may not have access to the command line, or you may install PHP using a local stack like XAMPP or WAMP.
You need to use the next method when this is the case.
Check PHP version using phpinfo()
If you can’t check the PHP version from the command line, then you can call the phpinfo()
function from a PHP page.
Let’s create a new file named phpinfo.php
with the following code:
<?php
phpinfo();
Save the file, then open it from the browser.