Let’s compile and install Apache 2.4.6 on CentOS 6.4!

First, you’ll need to install a few extra packages (if they aren’t there already):

yum install gcc
yum install make
yum install openssl-devel
yum install pcre-devel

Download httpd: http://httpd.apache.org/download.cgi

Download both apr and apr-utils: http://apr.apache.org/download.cgi

Unpack everything and move stuff into the right spots:

tar -xf httpd-2.4.6.tar.bz2

cp apr-1.4.8.tar.bz2 httpd-2.4.6/srclib/
cp apr-util-1.5.2.tar.bz2 httpd-2.4.6/srclib/

cd httpd-2.4.6/srclib/

tar -xf apr-1.4.8.tar.bz2
tar -xf apr-util-1.5.2.tar.bz2

mv apr-1.4.8 apr
mv apr-util-1.5.2 apr-util
cd ..

Now, we are ready to configure and compile Apache. There are a few schools of thought on this. My approach is to compile pretty much all the modules, and selectively load modules in the config. This gives me lots of flexibility. It’s nice to have modules ready to load if you need them. The number one module folks say they don’t need and then turn around and ask for 3 months later? mod_ssl. Number two is probably mod_rewrite. Also, note that I am installing to /usr/local/apache-2.4.6, not /usr/local/apache. This lets me deploy a new version of apache, cut over, and quickly roll back if any problems arise. It also gives me the opportunity to test the new version by running it next to the current version (on a different TCP port). Anyway, here are the commands:

./configure --with-included-apr \
            --enable-nonportable-atomics=yes \
            --enable-ssl \
            --enable-so \
            --prefix=/usr/local/apache-2.4.6

make

Time to install. The reason I use the symlink is so I don’t have to edit the start script every time I upgrade. Also, if there are multiple versions of apache installed, it’s easy to see which one is the active version.

make install
cd /usr/local/
ln -s apache-2.4.6 apache

That’s it for the install! Take a peek at /usr/local/apache/build/config.nice - that’s the command you used to do the compile! Very useful for troubleshooting. Now is a good time to wrap up a few loose ends: Create a dedicated user for Apache to run as, create logging and data directories, drop a log rotation file in /etc/logrotate.d, and install and enable a start script in /etc/init.d. Lastly, tuck into the config at /usr/local/apache/conf/httpd.conf. Good luck!