Building Apache HTTP server from source

Recently, I had to set up an Apache web server at work as part of a personal project. Since I was working on a remote machine without package install privileges, I had to try to build Apache from source packages only, without assuming too much from the system environment. It later turned out that another team had had the same project idea, and they had an actual budget. My personal resentment not withstanding however, building Apache was not as straightforward as I’d assumed. I’m documenting the process merely for reference and can be adjusted to the individual environment.

Environment

These steps were tested on boxes with the following environment. Machines missing any of the additional packages can remove the relevant build arguments where applicable (these should be self-evident later on).

  • OS: RHEL 6.8 / Ubuntu 18.04 LTS
  • Additional packages: mysql5.5, sqlite3
  • Source Packages to download:

Building packages

I’m going to assume that all the source packages are in $SRC_DIR. In addition, built packages are going to be installed into the $BUILD_DIR directory. For instance:

After extracting all the gzipped files, the build process itself is simply running CMMI (configure && make && make install) inside each of these directories, in order. Note that some packages depend on the binaries from building others. Below are the configure commands used to build each package.

$ cd expat-2.2.9
$ ./configure --prefix=${BUILD_DIR}/expat
$ cd pcre-8.44
$ ./configure --prefix=${BUILD_DIR}/pcre
$ cd zlib-1.2.11
$ ./configure --prefix=${BUILD_DIR}/zlib
$ cd apr-1.7.0
$ ./configure --enable-shared \
            --enable-threads \
            --enable-other-child \
            --prefix=${BUILD_DIR}/apr
$ cd apr-iconv-1.2.2
$ ./configure --with-apr=${BUILD_DIR}/apr \
            --prefix=${BUILD_DIR}/apr-iconv
$ cd apr-util-1.6.1
$ ./configure --with-apr=${BUILD_DIR}/apr/bin/apr-1-config \
            --with-iconv=${BUILD_DIR}/apr-iconv \
            --with-expat=${BUILD_DIR}/expat \
            --with-mysql=/ \   # `bin/mysql` will be appended to this value
            --with-sqlite3=/ \ # `bin/sqlite3` will be appended to this value
            --prefix=${BUILD_DIR}/apr-util
$ cd httpd-2.4.43
$ ./configure --enable-authn-anon \
            --enable-v4-mapped \
            --enable-authz-owner \
            --enable-auth-digest \
            --disable-imagemap \
            --enable-dav \
            --enable-dav-fs \
            --enable-dav-lock \
            --enable-deflate \
            --enable-expires \
            --enable-headers \
            --enable-info \
            --enable-mime-magic \
            --enable-proxy \
            --enable-proxy-ajp \
            --enable-proxy-http \
            --enable-proxy-ftp \
            --enable-proxy-balancer \
            --enable-proxy-connect \
            --enable-suexec \
            --enable-rewrite \
            --enable-so \
            --disable-userdir \
            --enable-vhost-alias \
            --with-mpm=prefork \
            --enable-mods-shared=all \
            --with-pcre=${BUILD_DIR}/pcre \
            --with-z=${BUILD_DIR}/zlib \
            --with-apr=${BUILD_DIR}/apr/bin/apr-1-config \
            --with-apr-util=${BUILD_DIR}/apr-util/bin/apu-1-config \
            --prefix=${BUILD_DIR}/httpd

Conventionally, the --prefix argument to ./configure is the directory where the compiled libraries and binaries will be stored. The --with-* arguments provide the location of dependent libraries; this is occasionally the build directory of the dependency, and at other times, a specific binary.

Running the server

That’s all to building the Apache HTTP server. To start the server, run:

$ ${BUILD_DIR}/httpd/bin/apachectl -k start

Apache tries to start up on port 80 by default, but it’s possible another application is already registered on that port. If so, open ${BUILD_DIR}/httpd/conf/httpd.conf and edit the port definition here:

# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
# Listen 12.34.56.78:80
Listen 80

That should get Apache running on your system. There’s a lot more to configure in the conf file including server name, virtual hosts, and DSO modules that provide additional functionality. To make sure Apache is running, note your system IP address, and try running http://<IP>:<conf port>/ in a browser. You should see something similar to the screen below:

Testing the server on a browser
You’re damn right it does!

And if it does, that’s 20 minutes well spent.