Compiling Apache 2.4 on Ubuntu 12.04

I’ve decided that I need to up my game when it comes to webservers. However I’m not yet ready to switch to Nginx or one of the other webservers out in the wild as I need something up and running rapidly.

Granted the numbers are definitely against Apache in a lot of benchmarks but historically I’ve always had a good experience and the entry level makes it much more appropriate for me to stick with it.

However Apache 2.2 is rather long in the tooth, thankfully 2.4 has been out for a while now. The problem I have is that I tend to favour Ubuntu as a platform and there is no sign of a 2.4 version appearing on the horizon anytime soon as they are waiting for it to be implemented upsteam in Debian before including it in Ubuntu.

Now there are PPAs available out there but im not overly happy using them (especially on production environments) So the only option is to compile.

First thing is to install all the dependencies we are going to need. Thankfuly ubuntu has a nice and simple way of handling this.

We can then download the source code and start the compilation.

So from the root of our new copy of the source we need to run our configure.

You will notice that I’m installing it using the event mpm. Hopefully I’ll be covering more about the event mpm in the future.

Next we need to run make

Once that’s complete you should be able to run

and get the “it works” message through your webrowser when accessing the server IP.

Dont forget to configure apache to suit your specific requirements.

Something that will come up is how to start apache on boot. Seeing as Ubuntu uses Upstart it makes sense to utilise it for controlling apache.

So in the file /etc/ini/apache.conf we need to put

This is a rather simple upstart script and I will be looking to update it at some point… but it works

Once that’s done you should find that on reboot Apache will start and take advantage of all the management features of upstart including attempting to respawn Apache should it end unexpectedly. You should also be able to then use the following commands to control Apache.

I generally tend to avoid using the apachectl script found at /usr/local/apache/bin/apachectl once upstart takes control.

Published by

Matt Cockayne

Matt is both a PHP Developer and Scout Leader. Having tried his hand a few different careers he finds that he is happiest working with code as the Technical Lead at Magma Digital. As a framework contributor and serial tinkerer Matt has spent a long time working on being the best PHP Developer he can be. As a Scout Leader he spends a lot of his time devoted to teaching valuable life skills to kids aged 7-18. He is a firm believer that being a Good Scout and Great Developer go hand in hand.

5 thoughts on “Compiling Apache 2.4 on Ubuntu 12.04”

    1. I will add that what Vidyadhar means is that if you want to manually compile Apache and all of its required dependencies (i.e. compile all the components installed by running ‘apt-get build-dep apache’) then his blog post is a good place find out how

  1. Thanks.  Pretty helpful.  I’m up and running with 2.4 now.  That said as a longtime ubuntu user there are a few differences with how config files and modules work.

    Ubuntu uses a couple of helper scripts, a2enmod and I think a2dismod to enable & disable modules, but really all they do is create and remove symbolic links.  With the default apache build given here you comment or uncomment lines in the config files.  That and it seems a lot of config files are not included by default, so I was left scratching my head as to why my changes weren’t being reflected.  Maybe it would be helpful to give a brief overview of modules & config?

    The next battle is with virtual hosts, but I can put that off till another day.

  2. Hi Joe,

    I’m glad the post managed to help.

    Your right in that Ubuntu does offer a lot of utilities to manage your Apache setup that are quite convenient (albeit as you have correctly pointed out they are just simple symlink creation scripts).

    The guide here is designed to give a more generic setup that comes directly from the Apache source meaning that the majority of the config is housed in /usr/local/apache2/conf/httpd.conf ` and will require you to un/comment lines as you need them.

    The default install deescribed here does put additional config into /usr/local/apache2/conf/extra which kinda simulates the setup of /etc/apache2/mods-enabled except that with the default config created from compiling you need to specifically uncomment the include for the file you need rather than just using Include conf/extra/*.conf

    Something to note though is that it wouldn’t take much to configure your installation to simulate the same layout as provided by the ubuntu packages using the --enable-layout= flag when you ./configure.

    With my virtual hosts, rather than use the conf/extra/httpd-vhost.conf file, I tend to create a /usr/local/apache2/sites.d folder and add the line Include sites.d/* to the bottom of my httpd.conf file. This means that I can create separate vhost files in there that are automatically picked up by apache.

    I’ll look at trying to add more detail in configuring Apache in a new post (if I can find the time)

Leave a Reply