7

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

aqw alhadary
  • 184
  • 1
  • 10

5 Answers5

2

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().

Community
  • 1
  • 1
Álvaro González
  • 142,137
  • 41
  • 261
  • 360
1

Maybe you could try

<?php
echo shell_exec('httpd -version');
Michael
  • 405
  • 4
  • 10
0

You can use $_SERVER['SERVER_SOFTWARE'] To get the the web server you're running. As Andrew said you can compile it yourself from here. There's no way around it

aqw alhadary
  • 184
  • 1
  • 10
0

To determine if you can read the Apache version, create a phpinfo.php file as mentioned by Álvaro González.

<?php phpinfo(); ?>

Run the file and if the PHP Variable $_SERVER['SERVER_SOFTWARE'] is listed with a value, use the following in your PHP code:

$apache_version = $_SERVER['SERVER_SOFTWARE'];
echo "$apache_version";

The reported value is dependent on the configuration and may not be listed at all. Otherwise you might get something like Apache/2.4.29 (Unix) or Apache/2.2.22 (Win64) etc.

Steve1200
  • 1
  • 3
-4
echo apache_get_version();

It will print the Apache's complete version detail.

Naveed Ramzan
  • 3,565
  • 3
  • 25
  • 30