3

I have upgraded to Apache 2.4 and I needed to change all

Order allow,deny
Allow from all

to

Require all granted

however, that caused those virtual host files to stop working on Apache 2.2.

Is there a way to write some IF in the configuration to get get same virtual host file to work for both versions?

9

You can use mod_version (link)

<IfVersion >= 2.4>
     Require all granted
</IfVersion>
<IfVersion < 2.4>
     Order allow,deny
     Allow from all
</IfVersion>
  • Thanks, this works too! Was wondering - would I be better off using IfVersion or IfModule as outlined in the answer I found? Thanks. – RandomWhiteTrash Dec 9 '14 at 7:20
  • 1
    My approach is the more flexible when it comes to versions. With the mod_authz_core version you just can check this is 2.4, but no sub versions and likely not that it might be 2.6 at some point. So I would prefer mod_version and only fall back to the other approach if that wouldn't be available. – Sven Dec 9 '14 at 7:25
  • Hm... actually I have to retract my earlier comment - this does not work in 2.2... I get following error: Invalid command '<IfVersion', perhaps misspelled or defined by a module not included in the server configuration.. am I doing something wrong? – RandomWhiteTrash Dec 9 '14 at 9:57
  • 2
    You have to make sure mod_version is installed and activated. Depending on your system, maybe you have to install a package. – Sven Dec 9 '14 at 9:59
  • 1
    It should be availabe already, you need to activate it. It would help if you would finally add some details about your environment to the question (e.g. the OS used and how you upgraded Apache). Use the edit button for this. – Sven Dec 9 '14 at 12:50
4

While waiting for an answer I seem to have found the solution:

<IfModule mod_authz_core.c>
   # Apache 2.4
   Require all granted
</IfModule>
<IfModule !mod_authz_core.c>
   # Apache 2.2
   Order deny,allow
   Allow from all
</IfModule>

Apparently you can check for existence of specific modules and make Apache2 do stuff accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.