Reputation: 287
How do I get the Apache version?
Actually, I want to use the setenv()
function in a PHP file, but I am not able to use that. It throws an error, undefined call to a function setenv()
. It might be because of my Apache version.
Upvotes: 9
Views: 20366
Reputation: 15949
You should be able to use the simple built-in php function apache_get_version()
;
from php manual :
<?php
$version = apache_get_version();
echo "$version\n";
?>
Edit Apr.2024
This is a very old answer was not tested in new PHP versions 7,8 etc.nor new Apache vr. or configurations - if someone tested please comment on results.
Upvotes: 4
Reputation: 13
The problem with apache_get_version() is that it depends on the settings on the server. Someone said it might return only "Apache" without the version but it also can return an error message like the "function apache_get_version() doesn't exist". That is exactly the problem I have. So I would use $_SERVER['SERVER_SOFTWARE'].
Correction: after trying $_SERVER['SERVER_SOFTWARE'], it shows it won't work on every server. On my live website, I get only "Apache" as a result there is no guarantee to work for some of us.
Upvotes: 0
Reputation: 26132
This will give you the version of Apache:
echo $_SERVER['SERVER_SOFTWARE'];
Upvotes: 2
Reputation: 2857
Here is a nice script for it: http://snipplr.com/view/10881/get-apache-version/
The Apache version is contained in the predefined variable:
$_SERVER['SERVER_SOFTWARE']
You could also use phpinfo() to get much information about the server, including all $_SERVER variables, activated modules and disabled functions.
Upvotes: 12