Tomcat with Apache Integration on Linux server

To make connection between Tomcat and Apache, you will need to download and install mod_jk connector.

Download the current source from the Apache archives:-

[root@map007]# cd /usr/local

[root@map007]# http://archive.apache.org/dist/jakarta/tomcat-connectors/jk/source/jk-1.2.6/jakarta-tomcat-connectors-jk-1.2.6-src.tar.gz

[root@map007 local]# tar -zxvf jakarta-tomcat-connectors-1.2.16-src.tar.gz

 Change to jakarta-tomcat-connectors-1.2.16-src/jk/native directory.

[root@map007 local]# cd /jakarta-tomcat-connectors-jk-1.2.6-src/jk/native

Now create the custom configure file for your system. Execute the following:

[root@map007 local]# ./buildconf.sh

[root@map007 local]# ./configure –with-apxs=/usr/sbin/apxs

Now build the mod_jk with the following:

[root@map007 local]# make

 Finally copy the newly created mod_jk.so to your Apache2 modules directory.

 [root@map007 /]# cp /root/jakarta-tomcat-connectors-jk-1.2.6-src/jk/native/apache-2.0/mod_jk.so /usr/lib/httpd/modules/

# Configuring Tomcat and Apache

[root@map007 /]# vi /etc/httpd/conf/workers.properties

workers.tomcat_home=/usr/lib/apache-tomcat
workers.java_home=/usr/lib/jdk
ps=/
worker.list=worker1
worker.default.port=8009
worker.default.host=localhost
worker.default.type=ajp13
worker.default.lbfactor=1

# Save and close the file.

# Now you have to configure httpd.conf file and following lines.

[root@map007 /]# vi /etc/httpd/conf/httpd.conf

LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so
# Where to find workers.properties
JkWorkersFile /etc/httpd/conf/workers.properties
# Where to put jk logs
JkLogFile /var/log/httpd/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the log format
JkLogStampFormat “[%a %b %d %H:%M:%S %Y] “

Save and close the file.

 Now a final security point.

[root@map007 /]# chown -R tomcat:tomcat /usr/lib/apache-tomcat

 # Now restart the Tomcat.

[root@map007 /]# cd /usr/local/tomcat/bin

[root@map007 bin]# ./shutdown.sh
[root@map007 bin]# ./startup.sh

 And restart Apache:

[root@map007 /]# /etc/init.d/httpd restart

Note: Always start Tomcat first before starting apache.

Posted in: Linux.
Last Modified: October 15, 2013

Leave a reply