Compile Apache Tomcat mod_jk on CentOS

Installing mod_jk on Apache.

[EDIT February 2024]: this article has been updated for CentOS/Rocky 9.

Software

Software used in this article:

  1. CentOS 9
  2. Apache 2.4
  3. Tomcat Connectors 1.2.49

Installation

# yum install httpd-devel apr apr-devel apr-util apr-util-devel gcc make libtool autoconf wget redhat-rpm-config

Get the latest source tarball:

# wget https://downloads.apache.org/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.49-src.tar.gz
# wget https://downloads.apache.org/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.49-src.tar.gz.sha512

Check the integrity of the file:

# sha512sum -c tomcat-connectors-1.2.49-src.tar.gz.sha512
tomcat-connectors-1.2.49-src.tar.gz: OK

Extract the archive:

# tar xf tomcat-connectors-1.2.49-src.tar.gz
# cd tomcat-connectors-1.2.49-src/native/

Get the path for apxs:

# which apxs
/usr/bin/apxs

Configure, compile and install:

# ./configure --with-apxs=/usr/bin/apxs
# make
# libtool --finish /usr/lib64/httpd/modules
# make install

Configuration

Open the file /etc/httpd/conf/workers.properties and add the following to reflect your application details:

worker.list=app1,app2

worker.app1.type=ajp13
worker.app1.host=app1.example.com
worker.app1.port=8201
worker.app1.socket_timeout=10

worker.app2.type=ajp13
worker.app2.host=app2.example.com
worker.app2.port=8201
worker.app2.socket_timeout=10

Open the file /etc/httpd/conf/httpd.conf and add the following:

LoadModule jk_module modules/mod_jk.so

JkWorkersFile "/etc/httpd/conf/workers.properties"
JkLogFile     "/var/log/mod_jk.log"
JkLogLevel  info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions     +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat     "%w %V %T"

Restart Apache. Check the log file mod_jk.log for any issues:

[Sun Dec 03 10:08:57 2017] [7005:140288381306848] [info] init_jk::mod_jk.c (3595): mod_jk/1.2.42 initialized

6 thoughts on “Compile Apache Tomcat mod_jk on CentOS

  1. Thank you for this useful cheatsheet. I’m not compiling mod_jk everyday so… this is a nice notes page.

  2. Also thank you for the Cheat Sheet, compiling from source to create an in-house RPM, you really helped make the first part easy! :)

  3. Thanks a lot – it still works.
    OS: Red Hat Enterprise Linux 8.5 (4.18.0-348.20.1.el8_5.ppc64le)
    SRC: tomcat-connectors-1.2.48-src.tar.gz

Leave a Reply to Zbyszek Cancel reply

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