Hosting providers are traditionally slow to adopt new PHP versions on their servers. Consequently, multiple different PHP versions can exist on the server at the same time.
If you are implementing new features, installing a new PHP-based app, or trying to locate a bug on your website, it is important to know which PHP version your web server is running.
In this article, you will learn how to check your PHP version on a local machine, server, or WordPress website.
Table of Contents
Check PHP Version by Running PHP Code

To check your PHP version by running code, you can use one of the following methods:
Method 1: Using phpinfo()
The phpinfo()
function outputs information about your PHP configuration, including the PHP version.
<?php
phpinfo();
?>
Steps:
- Save the above code in a file named
info.php
or something similar. - Place the file in your web server document root (e.g.,
/var/www/html
). - Open the file in a browser by visiting
http://your-domain.com/info.php
. - Look for the PHP version displayed at the top of the page.
Method 2: Using phpversion()
The phpversion()
function returns the current PHP version as a string.
Code:
<?php
echo 'Current PHP version: ' . phpversion();
?>
Steps:
- Save this code in a file, for example,
version.php
. - Place the file in your web server’s document root.
- Access it through your browser (e.g.,
http://your-domain.com/version.php
).

Method 3: Using the PHP_VERSION
Constant
PHP provides a predefined constant, PHP_VERSION
, that holds the current version of PHP.
Code:
<?php
echo 'Current PHP version: ' . PHP_VERSION;
?>
Steps: Same as Method 2.
Method 4: Command-Line Script
If you have access to the command line, you can write and execute a PHP script directly.
Command:
php -r "echo 'Current PHP version: ' . phpversion() . PHP_EOL;"

Best Practices
- Security: Avoid leaving files like
info.php
on your server in production, as they expose sensitive information about your configuration. - Testing: Use these methods in a controlled environment to avoid exposing your server to unnecessary risks.