9

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.

5 Answers 5

11

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.

Sign up to request clarification or add additional context in comments.

8 Comments

hello alexteg thanks for your reoly, i have used $_SERVER['SERVER_SOFTWARE'] but its only echoing 'Apache' & its not displaying version no. there. and i have also checked phpinfo() and used same function as given in your link but then also its not displaying any version no. Please suggest, am i making any silly mistake here ??
You can also try to use apache_get_version() php.net/manual/en/function.apache-get-version.php
$_SERVER['SERVER_SOFTWARE'] = "Apache"
The server/version string returned here is dependent on the Apache ServerTokens directive (which can only be set in the main server config, governing the whole server). If this is explicitly set to ServerTokens Prod then you will only get the string "Apache" returned to PHP.
@ObmerkKronen apache_get_version() does not work for me on php 7.4.33
|
6

apache2 -v from terminal at least in mint 17

1 Comment

Thank you. /usr/sbin/apache2 -V did the trick for me while the php based solutions did not work.
3

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.

3 Comments

Note that apache_get_version() - depends on settings in the httpd.conf file (ServerTokens). So, in relation to the settings, it can simply return Apache, without any version/details...
@Andron - thanks, I did not know that - and actually never crossed such server :-) . it always worked for me. but from now on I will do as accepted answer :-)
apache_get_version is always blank, may due to security
2

This will give you the version of Apache:

echo $_SERVER['SERVER_SOFTWARE']; 

1 Comment

Sadly, if ServerToken is set to "Prod", this just returns "Apache".
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.