How to Downgrade Apache to a Specific Version on Ubuntu (2.2 vs 2.4 Fix)


1 views

Ubuntu's package manager typically installs the latest stable version of Apache (currently 2.4.x), but legacy applications often require specific older versions like Apache 2.2. This version mismatch can break .htaccess rules, mod_rewrite behavior, and authentication modules.

First, completely remove your current Apache installation:

sudo apt-get purge apache2 apache2-utils apache2.2-bin apache2-common
sudo apt-get autoremove

Ubuntu maintains older packages in separate repositories. For Apache 2.2 on Ubuntu 18.04:

sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) main restricted universe multiverse"
sudo apt-get update

Now install Apache 2.2 with precise version pinning:

sudo apt-get install apache2=2.2.22-1ubuntu1.4 \
     apache2.2-common=2.2.22-1ubuntu1.4 \
     apache2.2-bin=2.2.22-1ubuntu1.4 \
     apache2-mpm-prefork=2.2.22-1ubuntu1.4

Prevent accidental upgrades with apt-mark:

sudo apt-mark hold apache2 apache2.2-common apache2.2-bin

Check your installed version:

apache2 -v

Important configuration differences to check:

# 2.2 vs 2.4 syntax example
Require all granted   # 2.4 syntax
Order allow,deny      # 2.2 syntax
Allow from all

For isolated environments, consider using Docker:

docker run -d -p 8080:80 --name apache22 httpd:2.2

Common modules that require version-specific installation:

sudo apt-get install libapache2-mod-php5=5.3.10-1ubuntu3.38
sudo a2enmod rewrite
sudo service apache2 restart

Always create a backup snapshot before major version changes:

sudo tar -czvf /backups/apache_config_backup.tar.gz /etc/apache2/

Many developers face issues when Ubuntu's package manager automatically upgrades Apache to newer versions (like from 2.2 to 2.4), potentially breaking existing configurations. The default apt-get install apache2 command always fetches the latest version, which might not be compatible with your legacy applications.

First, check available Apache versions in Ubuntu's repositories:

apt-cache policy apache2
apt-cache showpkg apache2

Use this syntax to install a specific Apache version:

sudo apt-get install apache2=2.2.22-1ubuntu1

If you need older versions not in the main repositories, you'll need to:

sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc)-updates main"
sudo apt-get update

Prevent accidental upgrades with:

sudo apt-mark hold apache2

To check held packages:

apt-mark showhold

For complete control, compile from source:

wget https://archive.apache.org/dist/httpd/httpd-2.2.34.tar.gz
tar -xzvf httpd-2.2.34.tar.gz
cd httpd-2.2.34
./configure --prefix=/usr/local/apache2
make
sudo make install

Check your installed version with:

apache2 -v

Or for more detailed information:

apachectl -V

Remember that Apache 2.2 and 2.4 have different configuration syntax. For example, access control changed from:

Order allow,deny
Allow from all

to:

Require all granted