phpversion
Returns a string containing the version of the currently running PHP parser or extension.
Parameters
An optional extension name.
Return Values
Returns the current PHP version as a string . If a string argument is provided for extension parameter, phpversion() returns the version of that extension, or false if there is no version information associated or the extension isn't enabled.
Changelog
| Version | Description |
|---|---|
| 8.0.0 | extension is nullable now. |
Examples
Example #1 phpversion() example
<?php
// prints e.g. ‘Current PHP version: 4.1.1’
echo ‘Current PHP version: ‘ . phpversion ();
// prints e.g. ‘2.0’ or nothing if the extension isn’t enabled
echo phpversion ( ‘tidy’ );
?>
Example #2 PHP_VERSION_ID example and usage
<?php
// PHP_VERSION_ID is available as of PHP 5.2.7, if our
// version is lower than that, then emulate it
if (! defined ( ‘PHP_VERSION_ID’ )) <
$version = explode ( ‘.’ , PHP_VERSION );
define ( ‘PHP_VERSION_ID’ , ( $version [ 0 ] * 10000 + $version [ 1 ] * 100 + $version [ 2 ]));
>
// PHP_VERSION_ID is defined as a number, where the higher the number
// is, the newer a PHP version is used. It’s defined as used in the above
// expression:
//
// $version_id = $major_version * 10000 + $minor_version * 100 + $release_version;
//
// Now with PHP_VERSION_ID we can check for features this PHP version
// may have, this doesn’t require to use version_compare() everytime
// you check if the current PHP version may not support a feature.
//
// For example, we may here define the PHP_VERSION_* constants thats
// not available in versions prior to 5.2.7
if ( PHP_VERSION_ID < 50207 ) <
define ( ‘PHP_MAJOR_VERSION’ , $version [ 0 ]);
define ( ‘PHP_MINOR_VERSION’ , $version [ 1 ]);
define ( ‘PHP_RELEASE_VERSION’ , $version [ 2 ]);
Notes
Note:
This information is also available in the predefined constant PHP_VERSION . More versioning information is available using the PHP_VERSION_* constants.
Note:
Some extensions may define their own version number. However, most bundled extension will use the PHP version as their version number.
Sorry, you have been blocked
This website is using a security service to protect itself from online attacks. The action you just performed triggered the security solution. There are several actions that could trigger this block including submitting a certain word or phrase, a SQL command or malformed data.
What can I do to resolve this?
You can email the site owner to let them know you were blocked. Please include what you were doing when this page came up and the Cloudflare Ray ID found at the bottom of this page.
Cloudflare Ray ID: 80410e66a9a42870 • Your IP: Click to reveal 178.175.133.131 • Performance & security by Cloudflare
Checking what PHP version I'm running on Linux?
I’m running Centos 5 and I need to know what version of PHP I’m running, is there a command for this which I can run?
4 Answers 4
Try running the following at the command line.
To just get the version information:
Or to get a lot of info:
It should give you all information you need about the php install.
You can make an index.php file with
An answer was accepted, but another option on RPM systems (RHEL, Centos, Fedora, etc.) is to use the following:
And while I’m at it, the general method for using RPM to find info on a package for any rpm-installed program or file is similar to this (for awk):
Find the full path to the file if not known, such as for an executable in $PATH:
Find the name, including version, of the package containing the file:
If desired, query for info from that package:
It’s a bit trickier for packages installed and used by Apache since they may not be on $PATH, but you can start with something like:
How to Check PHP Version (Apache, Nginx and CLI)
PHP (Hypertext Preprocessor) is a popular programming language generally used for web development. It was originally developed by the Danish-Canadian programmer Rasmus Lerdorf in the year 1994. It can be used either via the command line or used with popular web servers like Apache or Nginx. Apache has a PHP module to directly run PHP files but Nginx required a PHP-FPM package to work with PHP files.
This tutorial will help you to check the PHP version installed on your system. Also, what is the active version of PHP on the command line as well as the check PHP version used by Apache or Nginx? As we can install multiple PHP versions on a single system, it can be the there are different version’s active on CLI and Web servers.
Check PHP Version (CLI)
By default, there can be one default PHP version that can use with standard binary. To check the PHP version currently active on the command line, execute the following command on the terminal:
On Ubuntu and Debian systems, you can also access another version by pointing their versions like: php7.2 or php7.3 etc.
Check PHP Version (Apache/Nginx)
This is fine that, the current active PHP version on the command line is different than the version used by the Apache or Nginx web servers. It’s also possible that two virtual hosts can use different-2 PHP versions by using PHP-FPM.
So, to check the currently active version for Apache or Nginx, navigate to the document root of the website to which you want to check the PHP version. For example, my document root is “/var/www/html”:
Then create and edit a PHP script file in your favorite text editor:
And, add the following content to the files. Here we used built-in phpinfo() function, which prints the active PHP version details:
Press “CTRL +X” and hit Enter button. Then press ‘Y’ and again hit Enter to save and exit from text editor.
Next, open a web browser and access `https://localhost/phpinfo.php` URL. Update localhost with the IP address or the configured domain name on the system checking php version.
https://localhost/phpinfo.php

phpinfo() Function Result
The output will show you all the details related to active PHP along with the PHP version. It will show you the values of the PHP variables, a list of enabled PHP modules along with their version and other details.