Skip to content

Apache 2.4.6 Installation on Unix

Introduction

Apache HTTP Server has been the most widely used web server on the Internet since the early days of the World Wide Web. The first version of Apache was released in 1995, and it has been extensively developed and maintained by an open community of developers under the auspices of the Apache Software Foundation ever since.

Over the years Apache HTTP server has evolved with industry best practices for performance, security and extensibility. The latest major version, Apache 2.4, was released in 2012 with significant architectural improvements and support for the latest web protocols. Apache 2.4.6, released in 2014, provides numerous bug fixes and enhancements over the 2.4 mainline including:

  • Support for prefix name-based virtual hosting
  • Improved caching performance
  • Enhancements to the mod_proxy balancer manager
  • Allow configuration based on client attributes
  • Drops keep-alive connections with certain errors

In this comprehensive guide, we will cover downloading, compiling and installing Apache 2.4.6 from source on a Unix-based system. Compiling yourself rather than installing an existing binary allows you to optimize Apache for your specific platform and workload. It also provides more flexibility to tailor the capabilities and modules that are included.

We will also look at various configuration best practices around performance, security and compatibility. By the end of this guide you should have an in-depth understanding of Apache 2.4.6 and how to deploy and manage it for optimal results. Let‘s get started!

Downloading Apache 2.4.6

The latest stable release of the Apache HTTP Server is version 2.4.54 which was released on September 1st, 2022. However, in this guide we will specifically cover compiling and installing version 2.4.6 on a Unix system as an example.

You can download the 2.4.6 source code archive from the Apache Foundation‘s website:

https://archive.apache.org/dist/httpd/httpd-2.4.6.tar.gz

The archive contains the source code, documentation, scripts and other files needed to compile Apache from scratch.

Always verify you have downloaded the official archive and that it matches the provided cryptographic signature made by the Apache Release Manager with their long-term PGP key.

Here is the key fingerprint and signature for verifying httpd-2.4.6.tar.gz:

Key fingerprint = D6C4 8A39 5E55 25DA 51D5  13E4 4C2E CF0E 657B CEC7
Signature for httpd-2.4.6.tar.gz = e3a6eb71b79d2ad57c31cfb27f33fe4f8a9f059d

This protects against downloading a file that has been tampered with or is not what it claims to be.

I have downloaded httpd-2.4.6.tar.gz to my /tmp folder ready to be unpacked and compiled:

$ ls /tmp/httpd-2.4.6.tar.gz
/tmp/httpd-2.4.6.tar.gz

Prerequisites

Before compiling and installing Apache, we need to ensure we have all the required dependencies and tools on the system:

GCC Compiler

An ANSI-C compatible compiler like GCC is required as Apache is written in C code.

Install GCC:

$ sudo yum install gcc

Verify GCC version:

$ gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)

APR & APR-Util

The Apache Portable Runtime (APR) library provides an abstraction layer for common OS functionality across platforms. The companion APR-Util library builds on top of APR with additional utilities.

Install APR & APR-Util with yum:

$ sudo yum install apr apr-util apr-devel apr-util-devel

Check versions installed:

$ rpm -qa | grep -E ‘apr|apr-util‘
apr-1.7.0-9.el8.x86_64 
apr-util-1.6.1-7.el8.x86_64
apr-devel-1.7.0-9.el8.x86_64
apr-util-devel-1.6.1-7.el8.x86_64

OpenSSL

To support HTTPS connections, OpenSSL is required so that mod_ssl can leverage it.

Install the latest OpenSSL, compat libs and development files:

$ sudo yum install openssl openssl-devel openssl-libs

Confirm OpenSSL installed correctly:

$ openssl version
OpenSSL 1.1.1k  25 Mar 2021

libxml2

The libxml2 library is needed for supporting XML content such as with mod_lua.

Install libxml2 with yum:

$ sudo yum install libxml2-devel

curl

The curl library allows transferring files with URL syntax, required for things like mod_ftp.

Install curl:

$ sudo yum install curl-devel

Compiling the Apache Source

Now that we have all the required dependencies installed, we can proceed with unpacking, configuring and compiling the Apache source code.

First let‘s create a dedicated system user account called "httpd" which will run the Apache processes:

$ sudo useradd -r -s /sbin/nologin httpd

Also create a folder for Apache to be installed into:

$ sudo mkdir -p /usr/local/apache/2.4.6

Unpack the tar archive under /tmp, preserving permissions:

$ sudo tar xzf httpd-2.4.6.tar.gz -C /tmp

This will extract the source into /tmp/httpd-2.4.6 directory.

Now change to this directory for compiling:

$ cd /tmp/httpd-2.4.6

Run the configure script with appropriate options:

$ sudo ./configure \
  --prefix=/usr/local/apache/2.4.6 \  
  --with-apr=/usr/bin/apr-1-config \
  --with-apr-util=/usr \    
  --enable-mods-shared=most \
  --enable-deflate \
  --enable-ssl

This will prepare Makefile and other artifacts required for compiling with our chosen configurations – installing into the /usr/local/apache/2.4.6 folder, enabling a set of shared modules by default along with deflate and SSL support via OpenSSL.

Review the Configuration summary output to verify settings:

Server version  : Apache/2.4.6 (Unix) 
Architecture    : 64-bit  
System type     : linux-gnu
APR version     : 1.7.0  
APR flags       : (NONE)   
APR Util flags  : (LDAPS)
...
Modules enabled : 
  ab.c  
  alias.c  
  authn_core.c
  deflate.c 
  dir.c
  env.c
  headers.c
  log_config.c
  mime.c
  proxy.c
  rewrite.c
  setenvif.c  
  ssl.c 
  status.c

Now let‘s compile and install:

$ sudo make -j2
$ sudo make install

The -j2 option utilizes 2 CPU cores to speed up the compilation. Finally we install into the target directory with make install.

Cleaning up all the intermediary object files can save around 38MB:

$ sudo make clean

Our compiled Apache 2.4.6 is now installed into /usr/local/apache/2.4.6/ ready for configuration.

Configuring Apache

The main configuration file for Apache is located at /usr/local/apache/2.4.6/conf/httpd.conf. This manages the top-level server options, modules to load as well as includes additional site configuration snippets.

First, change ownership of the files to the httpd user and group:

$ sudo chown -R httpd:httpd /usr/local/apache/2.4.6/

Enable some commonly required modules by removing the # comment prefix:

LoadModule authz_host_module modules/mod_authz_host.so
LoadModule alias_module modules/mod_alias.so 
LoadModule rewrite_module modules/mod_rewrite.so

Setup a default HTTP host on port 80:

Listen 80

<VirtualHost *:80>
  DocumentRoot /var/www/html
  <Directory /var/www/html>
    AllowOverride All  
  </Directory>   
</VirtualHost>

Save changes and verify syntax is OK:

$ sudo /usr/local/apache/2.4.6/bin/apachectl configtest
$ sudo /usr/local/apache/2.4.6/bin/apachectl start

Apache should now be up and running. Test it out by accessing your server‘s IP address or domain in any web browser!

This covers the basics of installing and launching Apache 2.4.6 compiled from source. From here there are many directions for configuration – enabling more modules, adding virtual hosts, configuring caching, implementing SSL etc.

Conclusion

Compiling Apache HTTP server from source code allows for maximum control and optimization for your infrastructure. In this guide we have built Apache 2.4.6 from source on a Unix platform leveraging common tools like GCC and OpenSSL.

Covering the compilation process step-by-step aiming to provide key learnings for operating Apache in production:

  • What capabilities to enable from compilation flags and modules
  • How to configure the base server and initial host
  • Best practices for permissions and credentials

Apache remains a stellar, mature web server software after over 25 years. Yet with the major improvements in Apache 2.4 there is still more life for growth. Keep learning and applying all that open source has to offer!