To host a website/web pages on your machine you need a webserver software. Apache http server is widely used http server in the world.

You can install apache http server through apt repository, but this will install all modules which I dont require to host a simple webpage. For the same I am going to compile apache http server 2.4.1 from source package.

Step 1 : Before installing apache you have to install necessary prerequisite libraries and software. To do so open your command prompt and run following

sudo apt-get update
sudo apt-get install build-essential

Step 2 : Downloading pre-requisites. I am downloading all the required software to /home/vidyadhar/install folder. Here we are downloading apache http server 2.4.1 source, apr / apr util source and pcre lib source. Open a terminal and run following commands

cd /home/vidyadhar/install
wget http://apache.mirrorcatalogs.com//apr/apr-1.4.6.tar.gz
wget http://apache.mirrorcatalogs.com//apr/apr-util-1.4.1.tar.gz
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz
wget http://apache.tradebit.com/pub//httpd/httpd-2.4.1.tar.gz

Step 3 : Extracting source. Open a terminal and run following commands

cd /home/vidyadhar/install
tar zxvf httpd-2.4.1.tar.gz
tar zxvf pcre-8.30.tar.gz
tar zxvf apr-util-1.4.1.tar.gz
tar zxvf apr-1.4.6.tar.gz

Step 4 : Installing PCRE to /home/vidyadhar/pcre folder. Open a terminal and run following commands

cd /home/vidyadhar/install/pcre-8.30
./configure --prefix=/home/vidyadhar/pcre
sudo make
sudo make install

Step 5 : Copying apr and apr-utils to srclib of apache http server. Open a terminal and run following commands

cd /home/vidyadhar/install/
mv apr-util-1.4.1 /home/vidyadhar/install/httpd-2.4.1/srclib/apr-util
mv apr-1.4.6 /home/vidyadhar/install/httpd-2.4.1/srclib/apr

Step 6 : Installing apache http server to /home/vidyadhar/apache2.4 directory. Open a terminal and run following commands

cd /home/vidyadhar/install/httpd-2.4.1
./configure --prefix=/home/vidyadhar/apache2.4 --with-included-apr --with-pcre=/home/vidyadhar/pcre
sudo make
sudo make install

Step 7 : If everything goes well you have a working setup of apache 2.4.1 http server working setup. Before starting the http server you have to do some changes in the http server configuration i.e. in httpd.conf file.

Step 8 : First we will take the backup of original file

cd /home/vidyadhar/apache2.4/conf
cp httpd.conf httpd.conf.orig

Step 9 : Now you need to adjust following parameters as per your requirement.
Listen port, User / Group who will be running apache demon, ServerAdmin, ServerName.
I am going to run apache http server through “nobody” user. For the same first you have to create nobody user and group.

sudo useradd nobody
sudo grouadd nobody

Now same user you have to configure in httpd.conf file

User nobody
Group nobody

Step 10 : I am having multiple nic card on my machine and as per the requirement I will be running http server on 8080 port. So my Listen and ServerName directive should be something like below

Listen 192.168.1.100:8080
ServerName 192.168.1.100:8080

Step 11 : Before starting http server you should always test your configuration. Run following command to check you configuration.

/home/vidyadhar/apache2.4/bin/apachectl -f /home/vidyadhar/apache2.4/conf/httpd.conf -t

The idle output of above command should be Syntax OK

Step 12 : Now we are ready start our http server. Run following command to start http server

/home/vidyadhar/apache2.4/bin/apachectl -f /home/vidyadhar/apache2.4/conf/httpd.conf -k start

Now open your browser and enter http://192.168.1.100:8080 in URL.

Remember in above URL 192.168.1.100:8080 is the IP and PORT on which my http server listening.

If your are unable to start apache http server check for the http server logs which are located at /home/vidyadhar/apache2.4/logs folder

How to Install Apache 2.4.1 on Ubuntu

9 thoughts on “How to Install Apache 2.4.1 on Ubuntu

  • April 23, 2012 at 4:17 pm
    Permalink

    thanks for the instructions worked perfectly

    Reply
  • May 2, 2012 at 10:55 pm
    Permalink

    This worked perfectly compared to other guides out there. Worked well on my 11.10.

    Reply
  • May 8, 2012 at 7:39 pm
    Permalink

    Worked with absolutely no problem with Ubuntu Server 12.04 LTS.

    Reply
  • June 28, 2012 at 12:10 pm
    Permalink

    Hi Vidyadhar,
    Very nice tutorial on setting it up.
    I’m a newbie and I’ve one more requirement – setting up apache with LDAP. When I add –with-ldap and –enable-ldap to step 6 above, I get an error which says:

    configure: error: could not find an LDAP library
    configure failed for srclib/apr-util

    I tried –with-ldap-lib=/usr/lib but it didn’t help.

    I would really appreciate if you could guide me as to how to compile it with LDAP support.

    Thank you so much for your help!

    Reply
    • July 7, 2012 at 9:15 pm
      Permalink

      Hi,

      First install openldap on your server, then you can try to compile apache with ldap server

      Reply
  • Pingback:How to Install Apache 2.4.2 on Solaris | Adventures in Corporate World

Leave a Reply

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