Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get apache's version?

Tags:

php

apache

When I try to run apache_get_version() function on my website, I get an error:

Fatal error: Uncaught Error: Call to undefined function apache_get_version() in /srv/www/mywebsite.com/index.php:44 Stack trace: #0 {main} thrown in /srv/www/mywebsite.com/index.php on line 44

However this works in my localhost. I tried

function apache_version()
{
    $ver = explode(" ",$_SERVER["SERVER_SOFTWARE"],3);
    return ($ver[0] . " " . $ver[1]);
}
echo apache_version();

This should echo the server version on apache though it doesn't echo the version

like image 539
aqw alhadary Avatar asked Nov 26 '22 14:11

aqw alhadary


2 Answers

From the introduction to Apache functions:

These functions are only available when running PHP as an Apache module.

If you run PHP as CGI/FastCGI or any other SAPI, there's just no reliable way to determine Apache version because the interaction of PHP with Apache is minimum. If the server does not report it (thus you can read it somewhere at $_SERVER) you're out of luck.

You can also determine how PHP runs with phpinfo().

like image 105
Álvaro González Avatar answered Dec 06 '22 04:12

Álvaro González


Maybe you could try

<?php
echo shell_exec('httpd -version');
like image 35
Michael Avatar answered Dec 06 '22 04:12

Michael