If you are a Linux command line lover you can run this and see what version of PHP you are running:
1 |
php -i |
or you can alternatively run this to get strictly the version number
1 |
php -v |
Find PHP version on Windows
php -v is also working on Windows platforms. You can just start your CMD and run it to see the PHP version you currently have installed.
This will not work if you do not include php.exe in the system path. So if this is your case you will have to locate php.exe on your system. The Main is located here: C:\xampp\php
so I will run the set command using this path:
1 |
set PATH=%PATH%;C:\xampp\php\php.exe |
Now run again
php -v
and you should see your PHP version.
Find the PHP version when you do not have access to an SSH console.
When you do not have access to a command-line console you can find the PHP version using the phpinfo()
function.
Just put it in a new .php file and access it via your URL.
1 |
<?php phpinfo() ?> |
Or just a simpler way is to use the
phpversion()
specific function or the
PHP_VERSION constant.
1 2 3 4 |
<?php echo 'PHP version is: ' . phpversion(); echo 'PHP version is: ' . PHP_VERSION; ?> |
Why do I need to know my PHP version?
There are plenty of reasons Why you may be interested in the PHP version you are running. One would be that some functions are not available on some packages and other functions are deprecated on others.
If you want to know your PHP version and do something or something else depending on your release number you may be interested in using the compare like this.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
if (version_compare(PHP_VERSION, '7.0.0') >= 0) { echo 'I am at least PHP version 7.0.0, my version: ' . PHP_VERSION . "\n"; } if (version_compare(PHP_VERSION, '5.3.0') >= 0) { echo 'I am at least PHP version 5.3.0, my version: ' . PHP_VERSION . "\n"; } if (version_compare(PHP_VERSION, '5.0.0', '>=')) { echo 'I am at least PHP version 5.0.0, my version: ' . PHP_VERSION . "\n"; } if (version_compare(PHP_VERSION, '5.0.0', '<')) { echo 'I am still PHP 4, my version: ' . PHP_VERSION . "\n"; } |
Hope this helps you