Upgrading Apache 2.2 to Apache 2.4 on Debian or Ubuntu

2018-09-12

I have been asked several times at work by colleagues upgrading a Debian server why do they get a page not found (404) error on all their services hosted by Apache, without any error message and without having modified configuration files.
Having met the same problem before, and after struggling for a few hours before finally finding the obvious and dumb solution, here is a quick summary.

Configuration changes

Apache 2.4 on Debian and Ubuntu now only reads file with the .conf extension in the /etc/apache2/sites-enabled/ directory.

This is due to the new IncludeOptional directive which does not fail if no files are found, unlike the previous Include directive.
/etc/apache/apache2.conf now has:

# Include generic snippets of statements
IncludeOptional conf-enabled/*.conf

# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf

Fix

Simply rename all the good configuration files in /etc/apache2/sites-enabled/ to have the .conf extension. The best way to do that is to ensure that the configuration files in /etc/apache2/sites-available/ are all ok with a clean (empty) /etc/apache2/sites-enabled/ directory, and re-enable each configuration.

# Ensure that /etc/apache2/sites-enabled/ is empty
$ for i in /etc/apache2/sites-available/*
$ do
$     mv ${i} ${i}.conf
$     a2ensite ${i}
$ done

$ systemctl apache2 reload

More links

Excellent links on upgrading Apache 2.2 to Apache 2.4: