Integrate Tomcat with Apache – Easy Steps

In this tutorial, I am going to explain how can we integrate Tomcat with Apache. It’s very easy to integrate tomcat with apache.

Before integrating tomcat with apache, you should know “how to compile Apache on Linux“.

Overview

Tomcat8.5.X :

Some important points about Tomcat8.5.X,

Why should you now start installing or updating newer tomcat versions?

  • Because Tomcat team have announced the end of life date for Tomcat 8.0.x. Users of Tomcat 8.0.x should plan to upgrade before Tomcat 8.0.x reaches the end of life.
  • The Apache Tomcat team announces that support for Apache Tomcat 8.0.x will end on 30 June 2018.
  • You will get more information about Tomcat8.0.X on “https://tomcat.apache.org/tomcat-80-eol.html

I hope you go through Apache compilation steps.

Steps to integrate Tomcat with Apache

1. Download Tomcat and extract

$ cd /opt/
$ wget http://www-us.apache.org/dist/tomcat/tomcat-8/v8.5.32/bin/apache-tomcat-8.5.32.tar.gz
$ tar -xvf apache-tomcat-8.5.32.tar.gz [Learn more about Tar command]
$ mv apache-tomcat-8.5.32 tomcat8532

Below are the directories present under the extracted tar,

bin/
conf/
lib/
LICENSE
logs/
NOTICE
RELEASE-NOTES
RUNNING.txt
temp/
webapps/
work/

2. Install mod_jk.so and enable mod_jk module

mod_jk is an Apache httpd module used to make tomcat applications interact with an httpd server.

$ cd /opt/

$ wget http://www-us.apache.org/dist/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.43-src.tar.gz
$ tar -xvf tomcat-connectors-1.2.43-src.tar.gz [Learn more about Tar command]
$ cd /opt/tomcat-connectors-1.2.43-src/native
$ ./configure --with-apxs=/DATA/Apache2433/bin/apxs
$ make
$ make install

$ ll /DATA/Apache2433/modules/mod_jk.so [check mod_jk.so module is present or not after installation]

$ vim /DATA/Apache2433/conf/httpd.conf

# Add this line after the last LoadModule line

LoadModule jk_module modules/mod_jk.so

# Add below lines end of conf file

JkWorkersFile conf/workers.properties
# Where to put jk shared memory
JkShmFile logs/mod_jk.shm
# Where to put jk logs
JkLogFile logs/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the timestamp log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
#JkRequestLogFormat "%w %V %T"
#JkEnvVar SSL_CLIENT_V_START worker1

Save and exit

Before continuing, create the folder to store the shared memory of the module:

$ mkdir -p /var/run/mod_jk
$ chown apache:apache /var/run/mod_jk

if you do not create above directory it will throw below error,

[jk:emerg] [pid 19134:tid 140117029619584] Initializing shm:/var/run/httpd/mod_jk.shm.19134 errno=2. Unable to start due to shared memory failure.
$ /DATA/Apache2433/bin/apachectl graceful    [Reload Apache service]
$ /DATA/Apache2433/bin/apachectl -M          [Check mod_jk module enabled or not]

jk_module (shared)    [Module enabled successfully]

3. Configure workers.properties

$ vim /DATA/Apache2433/conf/workers.properties

# Add below lines,

worker.list=tomcat8532 [tomcat85 is the jvmroute for tomcat which used to route request through apache server]
##############################################
worker.tomcat8532.type=ajp13
worker.tomcat8532.host=localhost
worker.tomcat8532.port=8009
worker.tomcat8532.lbfactor=1

4. Configure VirtualHost for tomcat application on httpd,

$ vim /DATA/Apache2433/conf/extra/httpd-vhosts.conf

# Add below virtualhost entry and remove dummy host entry

<VirtualHost *:80>
ServerName localhost
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined
CustomLog /var/log/httpd/app1_access.log combined
ErrorLog /var/log/httpd/app1_error.log
<IfModule mod_jk.c>
JkMount /* tomcat8532
</IfModule>
</VirtualHost>

5. Configure Tomcat for integration

$ vim /opt/tomcat8532/conf/server.xml
# Add jvmRoute Parameter after defaulthost
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat8532">

save and exit

6. Start Tomcat service

$ cd /opt/tomcat8532/bin/
$ ./startup.sh

7. Browser URL :

You will get the Tomcat default page,

 

Tomcat with Apache

I hope you like the article if you find any difficulties then please do comment your queries or problem via the comment section, till then stay tuned to techthings.org for more such valuable articles.

Latest Comments
  1. Namesh July 8, 2018

Leave a Reply

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