Getting Tomcat and Apache working together isn’t very complicated as long as you know what to do!
Installation
- Enable multiverse repository
sudo apt-get install sun-java6-jdk apache2
sudo apt-get install tomcat5.5 tomcat5.5-admin tomcat5.5-webapps libapache2-mod-jk
sudo /etc/init.d/apache2 restart
sudo /etc/init.d/tomcat5.5 restart
Tests:
- Apache2: http://localhost
- Tomcat: http://localhost:8180
If you get an access error from the Tomcat test, it can usually be fixed by re-installing the sun java6 jdk, performing the Tomcat config below, and then restarting Tomcat: sudo apt-get install –reinstall sun-java6-jdk
Configure Tomcat
sudo nano -w /etc/tomcat5.5/tomcat-users.xml
<tomcat-users>
<role rolename=”admin” />
<role rolename=”manager” />
<role rolename=”tomcat” />
<user username=”tomcat” password=”tomcat” roles=”tomcat” />
<user username=”root” password=”password” roles=”admin,manager,tomcat” />
</tomcat-users>
sudo /etc/init.d/tomcat5.5 restart
Configure Apache to Tomcat Bypass
sudo cp /etc/libapache2-mod-jk/workers.properties /etc/apache2/
sudo nano -w /etc/apache2/workers.properties
#workers.tomcat_home=/usr/share/tomcat5
workers.tomcat_home=/usr/share/tomcat5.5#workers.java_home=/usr/lib/jvm/java-gcj
workers.java_home=/usr/lib/jvm/java-6-sun
sudo nano -w /etc/apache2/mods-available/jk.conf
# Where to find workers.properties
# Update this path to match your conf directory location (put workers.properties next to httpd.conf)
JkWorkersFile /etc/apache2/workers.properties
# Where to put jk shared memory
# Update this path to match your local state directory or logs directory
JkShmFile /var/log/apache2/mod_jk.shm
# Where to put jk logs
# Update this path to match your logs directory location (put mod_jk.log next to access_log)
JkLogFile /var/log/apache2/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] "
# Send everything for context /examples to worker named worker1 (ajp13)
JkMount /admin/* ajp13_worker
JkMount /manager/* ajp13_worker
sudo ln -s /etc/apache2/mods-available/jk.conf /etc/apache2/mods-enabled/jk.conf
sudo /etc/init.d/apache2 restart
Final Tests:
- Tomcat Admin: http://localhost/admin/
- Tomcat Manager: http://localhost/manager/html