Installing Apache 2.4.9 on CentOS 6

I decided to work out a little automated script to install the latest (as of this post) Apache web server on CentOS 6.  Anyone who knows CentOS knows that they back port security fixes into older versions, the default httpd is still on 2.2, apr is < 1.4 and who knows what else is messed up for dependencies if you wanted to use an Apache 2.4.x branch.  I’ve found a lot of sites and tutorials that were so-so on building out a 2.4.x system on CentOS 6 and with some trials and tribulations I finally came up with my own little, auto install script.

#!/bin/bash

### Script for installing apache 2.4.9, with session crypto module for encrypting cookies 
### Also installs dependencies; apr 1.5.1, apr-util 1.5.3, distache 1.4.5-23.
### Assumes logged in as root, with root home directory /root

# Setup RPM Build Environment
yum -y install rpm-build
mkdir -p ~/rpmbuild/{SOURCES,SPECS,BUILD,RPMS,SRPMS}

# Goto SOURCES path
cd ~/rpmbuild/SOURCES

# Check for source files, if not, get them and add to SOURCES

# Httpd
if [[ ! -f httpd-2.4.9.tar.bz2 ]]; then
    wget http://pkgs.fedoraproject.org/repo/pkgs/httpd/httpd-2.4.9.tar.bz2/2ef4e65353497606b24fa9bb3e5a3c40/httpd-2.4.9.tar.bz2
fi

# Apr
if [[ ! -f apr-1.5.1.tar.bz2 ]]; then
    wget http://pkgs.fedoraproject.org/repo/pkgs/apr/apr-1.5.1.tar.bz2/5486180ec5a23efb5cae6d4292b300ab/apr-1.5.1.tar.bz2
fi

# Apr-util
if [[ ! -f apr-util-1.5.3.tar.bz2 ]]; then
    wget http://pkgs.fedoraproject.org/repo/pkgs/apr-util/apr-util-1.5.3.tar.bz2/6f3417691c7a27090f36e7cf4d94b36e/apr-util-1.5.3.tar.bz2
fi

# Goto SRPMS path
cd ~/rpmbuild/SRPMS

# Get distache and put it in SRPMS
if [[ ! -f distcache-1.4.5-23.src.rpm ]]; then
    wget http://www.gtlib.gatech.edu/pub/fedora.redhat/linux/releases/18/Fedora/source/SRPMS/d/distcache-1.4.5-23.src.rpm
fi

# Install apr dependencies
yum -y install autoconf libtool doxygen expat expat-devel libuuid-devel db4-devel mysql-devel unixODBC-devel postgresql-devel sqlite-devel pcre pcre-devel lua-devel libxml2-devel openldap-devel nss-devel openssl-devel

# Make apr rpm
rpmbuild -tb ~/rpmbuild/SOURCES/apr-1.5.1.tar.bz2

# Install apr
rpm -ivh ~/rpmbuild/RPMS/x86_64/apr-1.5.1-1.x86_64.rpm ~/rpmbuild/RPMS/x86_64/apr-devel-1.5.1-1.x86_64.rpm

# Install RHEL repo for freetds
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

# Install freetds
yum -y install freetds freetds-devel glib

# Build apr-util rpm
rpmbuild -tb ~/rpmbuild/SOURCES/apr-util-1.5.3.tar.bz2

# Install apr-util et al.
rpm -ivh ~/rpmbuild/RPMS/x86_64/apr-util-1.5.3-1.x86_64.rpm ~/rpmbuild/RPMS/x86_64/apr-util-devel-1.5.3-1.x86_64.rpm ~/rpmbuild/RPMS/x86_64/apr-util-dbm-1.5.3-1.x86_64.rpm ~/rpmbuild/RPMS/x86_64/apr-util-pgsql-1.5.3-1.x86_64.rpm ~/rpmbuild/RPMS/x86_64/apr-util-mysql-1.5.3-1.x86_64.rpm ~/rpmbuild/RPMS/x86_64/apr-util-sqlite-1.5.3-1.x86_64.rpm ~/rpmbuild/RPMS/x86_64/apr-util-freetds-1.5.3-1.x86_64.rpm ~/rpmbuild/RPMS/x86_64/apr-util-odbc-1.5.3-1.x86_64.rpm ~/rpmbuild/RPMS/x86_64/apr-util-ldap-1.5.3-1.x86_64.rpm ~/rpmbuild/RPMS/x86_64/apr-util-openssl-1.5.3-1.x86_64.rpm ~/rpmbuild/RPMS/x86_64/apr-util-nss-1.5.3-1.x86_64.rpm

# Build distcache rpm
rpmbuild --rebuild ~/rpmbuild/SRPMS/distcache-1.4.5-23.src.rpm

# Install distcache
rpm -ivh ~/rpmbuild/RPMS/x86_64/distcache-1.4.5-23.x86_64.rpm ~/rpmbuild/RPMS/x86_64/distcache-devel-1.4.5-23.x86_64.rpm

# Build httpd rpm
rpmbuild -tb ~/rpmbuild/SOURCES/httpd-2.4.9.tar.bz2

# Need mailcap for mime types dependency
yum -y install mailcap

# Install httpd et al.
rpm -ivh ~/rpmbuild/RPMS/x86_64/httpd-2.4.9-1.x86_64.rpm ~/rpmbuild/RPMS/x86_64/httpd-devel-2.4.9-1.x86_64.rpm ~/rpmbuild/RPMS/x86_64/httpd-manual-2.4.9-1.x86_64.rpm ~/rpmbuild/RPMS/x86_64/httpd-tools-2.4.9-1.x86_64.rpm ~/rpmbuild/RPMS/x86_64/mod_authnz_ldap-2.4.9-1.x86_64.rpm ~/rpmbuild/RPMS/x86_64/mod_authnz_ldap-2.4.9-1.x86_64.rpm ~/rpmbuild/RPMS/x86_64/mod_lua-2.4.9-1.x86_64.rpm ~/rpmbuild/RPMS/x86_64/mod_proxy_html-2.4.9-1.x86_64.rpm ~/rpmbuild/RPMS/x86_64/mod_socache_dc-2.4.9-1.x86_64.rpm ~/rpmbuild/RPMS/x86_64/mod_ssl-2.4.9-1.x86_64.rpm

Just a copy and paste into a bash script and this guy should do the work for you!  Assuming it’s a fresh installation of CentOS 6 and that no apache server is already installed.

An upgrade from 2.2.x on the other hand, well that’s another matter.  I haven’t really done comments on my blog but turning them on for this post in case anyone has tweaks, suggestions or problems with this.

Maybe later on I will post on how to use some great features Apache 2.4 in fun and exciting ways, specifically mod_auth_form with mod_session_crypto. Once again, I’ve scoured the web looking for resources and examples on those, but wasn’t able to find a whole lot, so I figure I’ll share what I’ve come up with the next time I get around to doing a post.

Leave a Reply

Your email address will not be published. Required fields are marked *