Building Apache 2.2 from source for Ubuntu Dapper

Two reasons you might want to do this.

  1. You want to host a Rails application using Mongrel via Apache and mod_proxy_balancer.
  2. You’re studying in a Website administration module for your 3rd year Software Engineering degree :)

Seriously though, if you don’t want to use mod_proxy_balancer, just do a normal apt-get install of Apache 2 and you’ll be fine. mod_proxy_balancer is only available for Apache 2.2, and currently, that’s not available from the Ubuntu repositories via apt-get.

This article only covers installing Apache 2.2 – I’ll write another one for getting Subversion and PHP working shortly afterwards.

Workspace

If you’ve not got the build-essential package installed yet:

sudo apt-get install build-essential

It’s best to keep all of the source files in a seperate directory so they don’t mess up your home directory.

cd
mkdir src
cd src

Zlib

So that Apache can compress output to browsers that support it, we’re going to install Zlib first of all:

wget http://www.zlib.net/zlib-1.2.3.tar.gz
tar xvfz zlib-1.2.3.tar.gz
cd zlib-1.2.3/
./configure --prefix=/usr/local
make
sudo make install

Apache 2.2

Now download the Apache 2.2 source files:

cd ..
wget http://apache.rmplc.co.uk/httpd/httpd-2.2.3.tar.gz

Extract and move into the directory:

tar xvfz httpd-2.2.3.tar.gz
cd httpd-2.2.3/

Now to configure the build of Apache 2.2 that we want:

./configure --prefix=/usr/local/apache2 --enable-mods-shared=all --enable-deflate --enable-proxy --enable-proxy-balancer --enable-proxy-http

Besides setting the modules we’d like installed, and the location of the install, this paramater --enable-mods-shared=all is telling Apache 2.2 to build modules so that they can be dynamically loaded when it is started. This means, we can add further modules to our Apache 2.2 install when we like – as we will do with the Subversion modules and PHP.

Once the configuration is complete:

make
sudo make install

Let’s test that it’s working:

sudo /usr/local/apache2/bin/apachectl start

Now navigate to http://localhost and you should see a message saying “It works!”.

Stop Apache:

sudo /usr/local/apache2/bin/apachectl stop

Apache at start-up

Now let’s get Apache to start at boot time automatically:

sudo cp /usr/local/apache2/bin/apachectl /etc/init.d/apachectl
sudo chmod +x /etc/init.d/apachectl

What we’re doing here is copying the Apache Control script into the start-up directory.

We just need to add a few lines to the file for it to work nicely:

sudo nano /etc/init.d/apachectl

Add the followinig, so the top of the file looks like:

#!/bin/sh
#
# chkconfig: - 85 15
# description: Apache is a web server.

Save the file.

Now we need to register it with the start-up manager:

sudo /usr/sbin/update-rc.d apachectl defaults

Securing Apache

It’s also a good idea to create a dedicate Apache system user account. It’ll make your install much more secure.

sudo adduser --system apache

Now we just need to make sure that Apache runs under this user. We do that by editting the configuration file:

sudo nano /usr/local/apache2/conf/httpd.conf

You need to find the lines that say:

User daemon
Group daemon

And change them so they look like:

User apache
Group nogroup

Save the file.

Now, let’s start Apache:

sudo /usr/local/apache2/bin/apachectl start

Now to check it’s running under the new user, apache:

ps -aux | grep httpd

If you see the word apache in there, it’s working.

Check it’s all working

Now just reboot the system and before logging in, check on another machine by visiting the servers IP in the web browser and you should see the “It works!” message. This means Apache started up correctly automatically.

Building Apache 2.2 from source. Done.

2006-10-17 [, , , , , ]
  • Peter

    After running the following command sudo /usr/local/apache2/bin/apachectl start

    I get the following error: Syntax error on line 114 of /usr/local/apache2/conf/httpd.conf: Invalid command ‘Order’, perhaps misspelled or defined by a module not included in the server configuration

    Options FollowSymLinks AllowOverride None Order deny,allow # <– this is line 114 Deny from all

    Thanks

    Peter

  • http://davidwinter.me.uk David

    Try running this in the Terminal:

    cat /usr/local/apache2/conf/httpd.conf | grep mod_authz_host
    

    You should see a line appear as below:

    LoadModule authz_host_module modules/mod_authz_host.so
    

    Can you see that line?

  • Peter

    Thank you for the update,

    I gave up on Ubuntu and went back to Fedora Core 5

  • http://t800t8.net t800t8

    David,

    Can you help me to build Apache 2.2 from source with SSL? Thanks a lot.

  • http://thinedgeofthewedge.blogspot.com John Ward

    Hi David, Thanks for the pointers it was very helpful. One point regarding the steps outlined the download and compilation of zlib is not required as the zlib dev package will suffice.

    sudo apt-get install zlib1g-dev

    Running this first gets the necessary files, and it means one less moving part away from the package installer.

    John

  • Ajo Paul

    Hi,

    I am running Edgy, i removed apache2 installed from repo. But while i try to compile from from source using your steps, i get the following error message during make

    libtool: compile: unable to infer tagged configuration libtool: compile: specify a tag with `–tag’

    After this i would like to setup a svn 1.4 server using apache.

    Thanks in Advance, Ajo

  • asterixjowo

    Wow, this article is very useful. I am running Edgy. And apache2.2 works. I can see “it works” on http://localhost. But I have one question. How can I see my index.html from the other computer or world wide? I tried to give my ip but it did’t work. Thank you for the answer.

    GBU Asterixjowo

  • bernard

    @asterixjowo

    you will need to do a port forward in your router to point to your apache.

  • http://davidwinter.me.uk David

    You’ll need to forward port 80 on your router to your IP address on your local network.

    For me, my server is on 192.168.1.100

    On my router, I forward port 80 onto 192.168.1.100 — refer to your router manual on how to do that.

  • Monkey

    For those of you trying to compile on an AMD64, there is a bug in the Zlib makefile.

    After running ./configure in the zlib directory make sure this line is near the top of your Makefile:

    CFLAGS=-O2 -DUSE_MMAP -fPIC -m64

  • robl

    For i386 Ubuntu Dapper Apache2.2 packages see :

    http://www.kodefoo.com/2007/2/18/deploying-rails-on-ubuntu-dapper

  • http://www.cslog.cn xain

    How to remove apache2.0.55? I installed apache2.0.55 before I read this article. Following this article, I installed apache2.2.3 without removing apache2.0.55. Now apache2.2.3 won’t start — I was informed that the address had been taken. I used sudo apt-install remove apache2 to remove apache2.0.55, but it said apache2 wasn’t found on the system… what is wrong?

  • http://strivinglife.net/wordpress/2007/06/15/372/quickie-install-apache-224-on-ubuntu/ StrivingLife.net » Quickie: Install Apache 2.2.4 on Ubuntu

    [...] May not be the best, but … here’s how I installed Apache 2.2.4 on Ubuntu (7.04), based on this guide: http://davidwinter.me.uk/articles/2006/10/17/building-apache-22-from-source-for-ubuntu-dapper/ [...]

  • landon burch

    Thx.. I appreciate all the assistance.. not only did is provide solutions but I also got to run into a couple of issues which caused me to learn. tutorials like this help me to keep it open source..

  • Richard

    Thank you very much. There were great instructions that covered everything I needed to do! I appreciate it very much!

    As the guy above me says not only did it tell me what to do but I learned a couple things on the way and am getting very comfortable with the whole Linux thing. There’s nothing like the buzz you get when you’ve successfully compiled something from source.

  • Daan P

    Hi, i got my version of apache 2.2 working, but when i do apache2 -v i still get the old version and i can not do “a2enmod proxy_balancer”. I think this is still using the old apache 2.0.5 version, any idea how to fix this? (The “this works” line is visible after rebooting, so it’s the right apache2)

  • Tom

    You did a very good job describing Apache’s installation. Thank you very much.

  • http://pillvin.blogspot.com Vinod Pillai

    Awesome instructions. Thanks a lot!

  • http://apacheloadbalancer Hai

    Hello, I looking for instruction to setup an Apache Load Balancer using modProxybalancer. Have heard modproxybalancer could perform a load balancer proxy for three web sites. Could not find any step by step instruction how to set it up. Can you help.

  • Paul

    Hi David,

    Thanks for such an extensive article – I got it to work first time without problems!

blog comments powered by Disqus