C2B2 logo icon

How to install Apache and mod_jk

Very often on this blog, we mention Apache as a load balancer or proxy in relation to an application server like JBoss or Tomcat and take it for granted that readers will know exactly what we mean. This isn’t always

the case so, to get round that, we might mention in those blog posts that a quick web search will give you all the information you need.

Which is true.

It will.

But what if you don’t know what to search for? If you don’t know what we’re talking about in the first place, you’ll struggle to search intelligently and you might find that, although you end up with answers, you will more than likely take the long route to find them. This post aims to correct all that! We’ll show you the very basics of how to install Apache HTTP server and mod_jk ready to configure for load balancing.



What do you mean by “Apache”?
The first result on Google when I search for “Apache” is The Apache Software Foundation. You might find that a little confusing when, as in the first sentence of this blog, we tend to say “Apache” meaning a software product.
 

A typical basic load-balanced cluster

The answer is that, like the Hoover, Sellotape in the UK and Band-Aids in the USA, a company name has become synonymous with a product of that company. If you read “Apache” in an article which talks about a software product, it will almost universally be referring to the Apache HTTP server.

Apache is an open source community which looks after a range of software including Tomcat, which is the project which maintains mod_jk.


Wait, what’s mod_jk?
This is a middleware blog and mod_jk is where we enter the realm of middleware. I mentioned at the start the popularity of using Apache as a load balancer or proxy rather than just a server of static HTTP web pages. mod_jk is an Apache module which allows AJP communication between Apache and a back-end application server like GlassFish or JBoss. That’s really all it is – just another optional module for Apache that can forward the requests you specify from the HTTP server to a back-end application server, like JBoss in the diagram!


So how do I install the HTTP server?
Apache is by far the most dominant web server platform available today, far ahead of Microsoft’s IIS and the younger Nginx, so there is a huge amount of effort which goes in to making it as easy as possible to get up and running.

Linux
A lot of recent Linux distributions have package maintenance systems, dpkg for Debian, Yum for Red Hat and derivatives or Zypper (YaST) for SuSE. These all make it as easy as a couple of clicks in a GUI front-end or a single command in a terminal. Here’s an example with Ubuntu’s APT tool:
 

 sudo apt-get install apache2  


In the above example Apache HTTP server is provided in the repository by the name “apache2”. The naming will vary across Linux distributions but will likely be one of apache, apache2, or httpd.

Windows
Apache provide an msi installer for Apache HTTP server which will guide you through the basic steps in getting up and running, along with more advanced configuration steps. A popular alternative, is to use a pre-bundled solution to install and configure the popular W/L–AMP stack of [Windows or Linux], Apache, MySQL and PHP. A search for “WAMP installer” will bring up several options, including the imaginatively named WampServer.


Is that it?
Not quite! The mod_jk module isn’t included in the Apache HTTP server; it needs to be installed separately. Installation requires you to have the mod_jk module binary stored locally and visible to Apache and minor configuration to make sure Apache knows where to look for it and what to do with the requests you want mod_jk to proxy.

If you installed apache from Ubuntu’s default Universe APT repository, as above, you should find you have a directory structure like the one below:

 

 

 mike@ubuntu:/etc/apache2$ ll   total 88   drwxr-xr-x  7 root root 4096 Sep 2 09:27 ./   drwxr-xr-x 142 root root 12288 Sep 6 04:01 ../   -rw-r--r--  1 root root 9359 Jul 16 2012 apache2.conf   drwxr-xr-x  2 root root 4096 Sep 3 03:01 conf.d/   -rw-r--r--  1 root root 1322 Jul 16 2012 envvars   -rw-r--r--  1 root root 31063 Jul 16 2012 magic   drwxr-xr-x  2 root root 4096 Sep 3 02:53 mods-available/   drwxr-xr-x  2 root root 4096 Sep 3 02:53 mods-enabled/   -rw-r--r--  1 root root  750 Jul 16 2012 ports.conf   drwxr-xr-x  2 root root 4096 Sep 2 09:27 sites-available/   drwxr-xr-x  2 root root 4096 Sep 2 09:27 sites-enabled/  


Since you’ve already used APT to install Apache, it makes sense to use it again to install mod_jk! The package in Ubuntu’s repositories is called libapache2-mod-jk and is installed as follows:

 

 

 

 

 sudo apt-get install libapache2-mod-jk  


If you don’t already know the package name, you can search for it with APT or Yum if you’re using a RHEL based Linux:

 

 

 

 

 sudo apt-cache search <search_string>   sudo yum list <search_string>  


If you were to check either of the /etc/apache2/mods-… folders before and after installation, you will notice that two files have been added to the mods-available folder and symlinked to mods-enabled. These two files tell Apache about your mod_jk installation in (on Ubuntu) /etc/libapache2-mod-jk which is where you will need to configure the workers.properties file and httpd-jk.conf file when you want to use it with your application server.


Time to configure
By this stage, you have Apache http server installed and mod_jk available to it. If you want to actually use mod_jk for load balancing you will need to configure it further. That’s outside the scope of this blog post, though – we’ll always explain mod_jk configuration when we’re explaining clustering concepts specific to an application server. Andy Overton has already written about using mod_jk with JBoss EAP 5, and we have plans to write more in a similar vein in the future.