Get the Apache and PHP Version Info
Last Updated on: February 25, 2023
If you are developing PHP code for a website, you might sometimes want to check which version of Apache or PHP will be running the website. This is particularly true if you use some functionality that was included in a particular revision of the software or if you want to avoid security holes that were present in an older version.
There are two simple ways to get this information using phpinfo() or the SERVER_SIGNATURE:
phpinfo(); // will output a full info page with lots of information, including PHP and Apache version numbers
Or
echo $_SERVER[“SERVER_SIGNATURE”]; // useful if you want to use the version info in your code
Both of these will return much more information than just the Apache and PHP versions. One way to reduce the amount of information is to split the info returned by $_SERVER into an array and only keep the parts you are interested in. This approach is shown in the following example:
// Splits the text output into an array $ar = split("[/ ]",$_SERVER['SERVER_SOFTWARE']); // Loops through the array for ($i=0;$i<(count($ar));$i++) { switch(strtoupper($ar[$i])) { // Gets the Apache Version case 'APACHE': $i++; $Apache_Ver = $ar[$i]; break; // Gets the PHP Version case 'PHP': $i++; $PHP_Ver = $ar[$i]; break; }
As well as the Apache and PHP information obtained in the example, this approach can be used to obtain information about the software running on the server.
Get notified of new posts: