VirtualHost settings upgrading from Apache 2.2 to Apache 2.4.

Upgrading from Apache 2.2 to 2.4 is simply but some configuration updates are necessary, because a working Apache 2.2 VirtualHost setup will break silently when you upgrade to Apache 2.4.
A full and comprehensive guide to updating from Apache 2.2 to 2.4 is available in the apache.org website.

It is necessary to apply some changes to Apache 2.2 VirtualHost settings to make WebSites working again after upgrading to Apache 2.4. A ‘blind’ upgrade form Apache 2.2 to Apache 2.4 will fail for these mail two reasons:

  • VirtualHosts configuration files in the sites-available Apache’s directory must now use the .conf extension.
  • VirtualHosts configuration files must contain the Require all granted directive in directory block

In Apache 2.2 access control based on client hostname, IP address, and other characteristics of client requests was done using the directives Order, Allow, Deny, and Satisfy.
In Apache 2.4,such access control is done in the same way as other authorization checks, using the new module mod_authz_host. The old access control idioms should be replaced by the new authentication mechanisms.

Example: all requests will be denied.
Apache 2.2 configuration:

Order deny,allow
Deny from all

Apache 2.4 configuration:

Require all denied

Example: all requests are allowed.
Apache 2.2 configuration:

Order allow,deny
Allow from all

Apache 2.4 configuration:

Require all granted

Example: all hosts in the example.org domain are allowed, all other hosts are denied.
Apache 2.2 configuration:

Order Deny,Allow
Deny from all
Allow from example.org

Apache 2.4 configuration:

Require host example.org

Common symptoms that may indicate that it is needed to make changes to Apache 2.4 configuration as described, with possible solutions:

  • Symptom: When visiting your websites (VirtualHosted), the default It works! Apache web page appears.
    Solution: .conf extensions to virtual host needs to be added to configuration files and configuration files need to be re-enabled in sites-enabled directory by adding a symlink to their respective configuration files or by using a2ensite.
  • Symptom: When using a2ensite command, the error Site website.tld does not exist!.
    Solution: .conf extensions to virtual host needs to be added to configuration files and configuration files need to be re-enabled in sites-enabled directory by adding a symlink to their respective configuration files or by using a2ensite.
    a2en2site command needs to be invoked with full configuration file name (including .conf extension).
  • Symptom: 403 Forbidden error appears while accessing websites.
    Solution: The Require all granted directive is missing in the VirtualHost configuration files and needs to be added.

Comments are closed.