Monday, April 20, 2015

Apache 2.4.7 + Tomcat 7.0.42 Integration

Apache 2.4.7 + Tomcat 7.0.42 Integration

In this exercise we will setup Apache + Tomcat Integration
Install Apache from source
Download Apache 2.4.7 from
Download APR and APR UTIL from
untar apache
$ tar zxvf httpd-2.4.7.tar.gz
similarly untar apr and apr-utils and copy it to apahce/srclib folder
$ mv apr-1.5.0 httpd-2.4.7/srclib/apr
$ mv apr-util-1.5.3 httpd-2.4.7/srclib/apr-util
We plan to install apache in the /opt folder with all modules and DSO enabled.
./configure –prefix=/opt/apache247 –enable-mods-shared=all  –enable-so –with-included-apr
sudo make install
While configuring on an Ubuntu system, If you get error – “configure: error: pcre-config for libpcre not found”
This can be fixed by installing libpcre3-dev as follows :  sudo apt-get install libpcre3-dev
/opt/apache247/bin/apachectl start
Install Tomcat
untar to /opt/tomcatA
$ cd /opt/tomcatA
$ bin/
Install/Configure mod_jk/AJP connectors
Download the ajp connector from
$ cd tomcat-connectors-1.2.37-src/native
$ ./configure –with-apxs=/opt/apache247/bin/apxs
$ make
Next copy the from tomcat-connectors-1.2.37-src/native/apache-2.0
to /opt/apache247/modules/
$ sudo cp /opt/apache247/modules/
Configuring mod_jk.conf file
Edit httpd.conf
Add the following at the last of the LoadModule section
LoadModule jk_module modules/
At the bottom of the file , add the following line
Include conf/mod_jk.conf
Next, create the mod_jk.conf file
# Where to find
JkWorkersFile /opt/apache247/conf/
# location of log file
JkLogFile /opt/apache247/logs/mod_jk.log
# log level
JkLogLevel info
# Select the log format
JkLogStampFormat “[%a %b %d %H:%M:%S %Y]”
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat “%w %V %T”
#Send everything for context /test to worker ajp13
JkMount /test tomcatA
JkMount /test/* tomcatA
NOTE: if you are pasting above directly to you config file, please ensure the double-quotes are in proper format after copy-paste or edit them before restarting apache.
# Define workers
# Set properties
Testing the Integration
Lets create a test file
mkdir test
cat ping.jsp
Direct Testing to confirm it works with Tomcat
Testing the integration by accessing it via Apache
Tail the mod_jk.log
tail -f mod_jk.log
You should see something like this
[Sun Nov 24 02:34:11 2013]tomcatA localhost 0.056210
Integration is working as expected.