I want to write a configuration for an apache server which should work for apache-2.2 and -2.4 without alterations. Since there are a quite a few new modules in v2.4 which have to be loaded,and a few altered directives, I will need some conditional statements. What I'd like is something along the lines of
<If ApacheVersion >= 2.4>
LoadModule mod_only_in_2.4.so
</If>
but I haven't found the right expression yet. Can somebody point me in the right direction?
Clarification of my motives: I am developing a server which I want to be able to just copy onto a server and run without further host-dependent configuration. And since the machines can have either version of apache, I want a configuration which works in both cases.
You should be checking for the module, not the Apache version.
For instance:
Note that you can't guess in advance whether someone has a specific Apache version; it's up to the sysadmin to make sure that the correct modules are being loaded. As the developer all you really need to worry about is that you are providing the correct directives, depending on what modules are available.
As a sysadmin you will have to maintain differing configurations for Apache 2.2 and 2.4; there is no way around this. Fortunately every configuration management system makes this relatively easy, and if you aren't already using such a system, you should be.
If
mod_version
is loaded, which should be available by default (although not loaded by default) in both Apache 2.2 and 2.4, you can use the<IfVersion>
directive to check for Apache's (and only Apache's) version:Example taken from the documentation.
Here's what I ended up doing: I edited my start script to set a variable specifying the apache version
and in the apache configuration I checked for those definitions