RSS feed for this blog

Upgrading from Apache 2.2 to Apache 2.4

By Paul Watson on .

A bit more technical than my usual posts here, but…

I upgraded to Kubuntu 13.10 on Thursday evening on my desktop machine at home, and one of the packages included in the update was Apache (Apache 2.2 upgraded to Apache 2.4).

Just in case any of you upgrade to Apache 2.4 in the future I thought I’d warn you that every damn vhost file in the sites-available directory needs to be manually edited to change the Authorization configurations to use new commands:

Apache 2.2 configuration:
Order allow,deny
Allow from all

Apache 2.4 configuration:
Require all granted

Near the bottom of the apache.conf file for Apache2.4 is this line:

IncludeOptional sites-enabled/*.conf

So you either need to make sure that your vhost files in /sites-enabled have a “.conf” file suffix or, if you’re lazy like me, you need to edit that line to:

IncludeOptional sites-enabled/*

More information at http://httpd.apache.org/docs/trunk/upgrading.html

Another stumbling block I came across is that the FilterProvider directive has changed from Apache 2.2 and is not backwards compatible: the match and dispatch arguments are replaced with a single expression. I was using this in a .htaccess file for one of my sites.

Annoyingly, while my desktop DEV box at home is now on Apache 2.4, the web hosting company I use are still on Apache 2.2.

If any of you hit the same problem, the solution (at least in a .htaccess file) is to provide both the Apache 2.4 commands inside a <IfVersion >= 2.4></IfVersion>, and the Apache 2.2 commands inside a <IfVersion <= 2.2></IfVersion> as below (hat-tip for this solution goes to the HTML5 Boilerplate project):

<IfModule version.c>
 <IfModule filter_module.c>
    <IfVersion >= 2.4>
      FilterDeclare   COMPRESS
      FilterProvider  COMPRESS  DEFLATE "%{CONTENT_TYPE} = 'text/html'"
      FilterProvider  COMPRESS  DEFLATE "%{CONTENT_TYPE} = 'text/css'"
      FilterProvider  COMPRESS  DEFLATE "%{CONTENT_TYPE} = 'text/plain'"
      FilterProvider  COMPRESS  DEFLATE "%{CONTENT_TYPE} = 'text/xml'"
      # etc
      FilterChain     COMPRESS
      FilterProtocol  COMPRESS  DEFLATE change=yes;byteranges=no
    </IfVersion>
    <IfVersion <= 2.2>
      FilterDeclare   COMPRESS
      FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/html
      FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/css
      FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/plain
      FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/xml
      # etc
      FilterChain     COMPRESS
      FilterProtocol  COMPRESS  DEFLATE change=yes;byteranges=no
    </IfVersion>
  </IfModule>
 </IfModule>

This block will now work on both Apache 2.2 and Apache 2.4

The actual changes to get my sites running on my DEV box took me about 10 minutes to make (and 2-3 hours to research them, change something, restart Apache, see the next error, swear, do more research…)