Labels

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 http://httpd.apache.org/download.cgi
Download APR and APR UTIL from http://apr.apache.org/download.cgi
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
make
sudo make install
NOTE:
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
Testing
/opt/apache247/bin/apachectl start
Install Tomcat
untar to /opt/tomcatA
$ cd /opt/tomcatA
$ bin/startup.sh
Testing
Install/Configure mod_jk/AJP connectors
Download the ajp connector from http://tomcat.apache.org/download-connectors.cgi
$ cd tomcat-connectors-1.2.37-src/native
$ ./configure –with-apxs=/opt/apache247/bin/apxs
$ make
Next copy the mod_jk.so from tomcat-connectors-1.2.37-src/native/apache-2.0
to /opt/apache247/modules/
$ sudo cp mod_jk.so /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/mod_jk.so
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 workers.properties
JkWorkersFile /opt/apache247/conf/workers.properties
# 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.
Configure workers.properties
# Define workers
worker.list=tomcatA
# Set properties
worker.tomcatA.type=ajp13
worker.tomcatA.host=localhost
worker.tomcatA.port=8009
Testing the Integration
Lets create a test file
/opt/tomcat7A/webapps/
mkdir test
cat ping.jsp
pong
Direct Testing to confirm it works with Tomcat
http://localhost:8080/test/ping.jsp
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.