When running apt-get install apache2
on Debian Wheezy, you'll get Apache 2.2 by default since that's what the official repositories provide. This can be problematic if you need specific features from Apache 2.4 like improved performance, better reverse proxy handling, or enhanced authentication modules.
The most reliable way to get Apache 2.4 on Wheezy is through the Dotdeb repository which provides updated packages for Debian:
# Add Dotdeb to your sources.list
echo "deb http://packages.dotdeb.org wheezy all" >> /etc/apt/sources.list
echo "deb-src http://packages.dotdeb.org wheezy all" >> /etc/apt/sources.list
# Add the GPG key
wget https://www.dotdeb.org/dotdeb.gpg
apt-key add dotdeb.gpg
# Update and install
apt-get update
apt-get install apache2
After installation, verify you have the correct version:
apache2 -v
# Should output something like:
# Server version: Apache/2.4.10 (Debian)
# Server built: Jul 30 2022 12:25:09
If you prefer compiling from source, here's a basic procedure:
# Install dependencies
apt-get install build-essential
apt-get build-dep apache2
# Download and extract
wget https://downloads.apache.org/httpd/httpd-2.4.54.tar.gz
tar -xzvf httpd-2.4.54.tar.gz
cd httpd-2.4.54
# Configure and make
./configure --prefix=/usr/local/apache2 --enable-mods-shared=most
make
make install
Apache 2.4 has several configuration syntax changes from 2.2. For example, access control:
# Apache 2.2 style:
Order allow,deny
Allow from all
# Apache 2.4 style:
Require all granted
And for authentication:
# Apache 2.2:
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
# Apache 2.4:
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
If you encounter errors after installation:
- Check
/var/log/apache2/error.log
for specific error messages - Run
apache2ctl configtest
to validate your configuration - Ensure all needed modules are enabled with
a2enmod
Debian Wheezy's official repositories ship with Apache 2.2.22 by default, which is problematic for developers needing newer features like HTTP/2 support, improved reverse proxy handling, or enhanced security models available in 2.4+. The standard apt-get install apache2
won't suffice here.
First, enable Wheezy backports in your sources.list:
echo "deb http://http.debian.net/debian wheezy-backports main" | sudo tee -a /etc/apt/sources.list
Then update and install:
sudo apt-get update
sudo apt-get -t wheezy-backports install apache2
If backports aren't available, compile from source:
wget https://archive.apache.org/dist/httpd/httpd-2.4.57.tar.gz
tar -xvf httpd-2.4.57.tar.gz
cd httpd-2.4.57
./configure --prefix=/usr/local/apache24 --enable-ssl --enable-so
make
sudo make install
Create a systemd service file at /etc/systemd/system/apache2.service
:
[Unit]
Description=Apache 2.4 Web Server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/apache24/bin/apachectl start
ExecStop=/usr/local/apache24/bin/apachectl stop
[Install]
WantedBy=multi-user.target
When upgrading from 2.2 to 2.4, pay special attention to:
- Require directives now need explicit authorization (
Require all granted
vs old Allow/Deny)
- New
IfDefine
syntax and stricter SSL configuration
Example virtual host update:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted # Critical change from 2.2
</Directory>
</VirtualHost>
After installation, check the version:
apache2 -v
# Should return: Server version: Apache/2.4.x (Debian)
Test the configuration:
apachectl configtest