How to Check the PHP Version

PHP versions differ in features, performance, and security support. Before installing an application or upgrading your stack, you will often need to confirm which version is active on your server.
This guide shows two ways to do that: through the browser using phpinfo(), and from the command line using the PHP binary.
Checking PHP version with phpinfo()
The most reliable way to find out which PHP version is used for a specific website is the phpinfo() function. It prints a full summary of the PHP configuration, including the version number.
In your website document root, create a small PHP file using an FTP or SFTP client:
<?php
phpinfo();Open your browser, navigate to yourdomain.com/phpinfo.php, and the PHP version will appear at the top of the page:

Once you have noted the version, remove the file or restrict access to it. Leaving phpinfo() output publicly accessible exposes your server configuration and can create a security risk.
If you only need the version number without the full configuration dump, use phpversion() instead:
<?php
echo 'PHP version: ' . phpversion();Checking PHP version from the Command Line
If you have SSH access to the server, you can check the PHP version directly from the terminal. Run the php binary with the --version or -v flag:
php --versionThe command prints the version and exits:
PHP 8.3.4 (cli) (built: Mar 15 2024 09:07:22) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.4, Copyright (c) Zend Technologies
with Zend OPcache v8.3.4, Copyright (c), by Zend TechnologiesIn this example, the server is running PHP 8.3.4.
Keep in mind that if multiple PHP versions are installed, the php command shows the version of the default CLI binary, which may differ from the version your web server is actually using.
Conclusion
The command line is the quickest way to check PHP version on a server you have SSH access to. For hosted environments where you only have FTP access, phpinfo() gives you everything you need.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page