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.
<IfModule mod_authz_core.c> Require all granted </IfModule> <IfModule !mod_authz_core.c> Order deny,allow Allow from all </IfModule>
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.
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.