Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect Apache version in apache config?

Tags:

tl;dr: How do I do the following in a .conf or .htaccess file:

<IfApache22>   # Do A </IfApache22> <IfApache24>   # Do B </IfApache24> 

Longer question:

With Apache 2.4 the old Order get's deprecated in favor of Require.

In my .htaccess files I have

<FilesMatch "\.(long|list|file|types)$">   Order allow,deny </FilesMatch> 

which means Apache fails to start unless I enable access_compat. While doing so presents a useful workaround, I want a solution that works with both syntaxes as the config will be distributed to a lot of servers. The question is how I can detect the current version of Apache and apply the correct directive.

I intend to use the file for a framework that is distributed to and used by a lot of people, and I can't control/guarantee that they have or lack any particular server setup, which is why I'd like the file to be 2.2/2.4 "agnostic".

like image 356
Letharion Avatar asked May 22 '12 17:05

Letharion


2 Answers

A hack that I have used.

# Apache 2.2 <IfModule !mod_authz_core.c>     Satisfy Any </IfModule>  # Apache 2.4 <IfModule mod_authz_core.c>     Require all granted </IfModule> 
like image 186
Mark Avatar answered Oct 23 '22 11:10

Mark


Assuming you have mod_version installed (many distributions ship it by default) you can do the following:

<IfVersion >= 2.4>     # Require ... </IfVersion> <IfVersion < 2.4>     # Order ...     # Deny ...     # Allow ... </IfVersion> 
like image 24
weirdan Avatar answered Oct 23 '22 12:10

weirdan