Skip to content
Bots!
Bots!
  • About
    • Myself
    • আমার দোয়া
  • Bookmarks
    • Bookmarks
    • My OCI Bookmarks
    • Useful Proxmox Commands & Links
    • Learning Nano
    • Useful Sites
    • Useful Virtualbox Command
    • Useful MySQL Command
    • Useful Linux Command
    • BTT-CAS
  • Resources
    • Webinar on Cloud Adoption for Project Managers
  • Photos
  • Videos
  • Downloads
Bots!

Setup Tomcat with Apache2 and Java on Ubuntu 10.04 Server

Rumi, May 28, 2011May 28, 2011
Apache Tomcat (or Jakarta Tomcat or simply Tomcat) is an open source servlet container developed by the Apache Software Foundation (ASF). Tomcat implements the Java Servlet and the JavaServer Pages (JSP) specifications from Sun Microsystems, and provides a "pure Java" HTTP web server environment for Java code to run.
 
Tomcat should not be confused with the Apache web server, which is a C implementation of an HTTP web server; these two web servers are not bundled together. Apache Tomcat includes tools for configuration and management, but can also be configured by editing XML configuration files.
 
1 Preliminary Note
This tutorial is based on Ubuntu 10.04 Server (Lucid Lynx), so you should set up a basic Ubuntu 10.04 server installation with Apache or a LAMP Server before you continue with this tutorial The system should have a static IP address. I use 192.168.1.100 as my IP address in this tutorial and server1.example.com as the hostname.
Make sure that you are logged in as root (type in
sudo su
(to become root), because we must run all the steps from this tutorial as root user.
 2 Installing Java Development Kit (JDK)
For easily adding a repository now and in the future you must install python-software-properties first:
apt-get install python-software-properties
Then run:
add-apt-repository "deb http://archive.canonical.com/ubuntu lucid partner"
Now update the Aptitude cache:
apt-get update
We will now install sun-java6-jdk which is available in the new repository, and openjdk-6-jdk:
apt-get install sun-java6-jdk openjdk-6-jdk
Accept the license agreement! with Ok and then Yes!
Let's make sure Ubuntu and our future Tomcat check the sun-java6-jdk package first:
update-alternatives –config java
Choose the number that matches with /usr/lib/jvm/java-6-sun/jre/bin/java
Now check the Java version by typing:
java -version
It should look a lot like this (depends on java version in repo!)
root@ubuntu:~# java -version
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03, mixed mode)
 3 Installing Tomcat6
We can install Tomcat 6 via Aptitude like this:
apt-get install tomcat6 tomcat6-admin tomcat6-common tomcat6-docs tomcat6-examples tomcat6-user
 3.1 Declaring users and roles
Usernames, passwords and roles (groups) can be defined centrally in a Servlet container.
In Tomcat 6.0 this is done in the /etc/tomcat6/tomcat-users.xml file:
vi /etc/tomcat6/tomcat-users.xml
and add the following:
<role rolename="manager"/>
<role rolename="admin"/>
<user username="YOUR_USERNAME" password="YOUR_PASSWORD" roles="manager,admin"/>
 
Make sure you replace YOUR_USERNAME and YOUR_PASSWORD with your credentials, then save and exit the file.
3.2 Restart Tomcat6 and have a first test
/etc/init.d/tomcat6 restart
Then use your browser to visit http://192.168.1.100:8080/ and verify that you get the default Tomcat page.
You should also be able to visit http://192.168.1.100:8080/manager/html with the credentials you have set above:
http://static.howtoforge.com/images/tomcat6_sun_java_apache2_ubuntu_10.04/HQeQ2.png
4 Integrate Tomcat6 on Apache2
First we install the Apache2 connector for the Tomcat Java servlet engine like this:
apt-get install libapache2-mod-jk
 4.1 Configure the connector module
Now we can start configuring the connector module, first we create a new file which will hold our properties:
nano /etc/apache2/workers.properties
Add the following to the file:

workers.tomcat_home=/var/lib/tomcat6

workers.java_home=/usr/lib/jvm/java-6-sun
ps=/
worker.list=default
worker.default.port=8009
worker.default.host=localhost
worker.default.type=ajp13
worker.default.lbfactor=1

Save and exit the file.

4.2 Configure Apache2 to use the connector properties
Create a configuration file for Apache2 which will load when Apache starts:
nano /etc/apache2/conf.d/mod_jk.conf
Add the following to the file:
<IfModule mod_jk.c>

 JkWorkersFile /etc/apache2/workers.properties
 JkShmFile /var/log/apache2/mod_jk.shm
 JkLogFile /var/log/apache2/mod_jk.log
 JkLogLevel info
 JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
 JkRequestLogFormat "%w %V %T"
</IfModule>

 

Save and exit the file.
4.3 Setup a new virtual host in Apache2
Create the folders for our new virtual host:
mkdir /var/www/server1.example.com
mkdir /var/www/server1.example.com/htdocs
mkdir /var/www/server1.example.com/logs
Then create a new site in Apache2:
nano /etc/apache2/sites-available/server1.example.com
Then add:
<VirtualHost *:80>

    JkMount /* default
    ServerName server1.example.com
    ServerAdmin webmaster@server1.example.com
    DocumentRoot /var/www/server1.example.com/htdocs
    ErrorLog /var/www/server1.example.com/logs/error.log
    CustomLog /var/www/server1.example.com/logs/access.log combined
    <Directory /var/www/server1.example.com/htdocs>
        Options -Indexes
    </Directory>
</VirtualHost>

 

Note: JkMount can be setup in different ways.
JkMount /* will use tomcat for all files
JkMount /*.jsp only for .jsp files
JkMount /folder/* for tomcat files in a specific directory
Enable the new virtual host we created, by running:
a2ensite server1.example.com
4.4 Setup a the new virtual host in Tomcat6
Open up the configuration file for Tomcat6:
nano /etc/tomcat6/server.xml
Find the following lines:
<!–

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
-->

And uncomment the connector port, like this: <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

Then scroll down and find: </Host>

</Engine>

 

AFTER the ending </Host> tag, and BEFORE the ending </Engine> tag, insert the following:
<!– server1.example.com –>

<Host name="server1.example.com" appBase="/var/www/server1.example.com" unpackWARs="true" autoDeploy="true">
    <Context path="" docBase="htdocs" debug="0" reloadable="true"/>
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="/var/www/server1.example.com/logs" prefix="tomcat_access_" suffix=".log" pattern="common" resolveHosts="false"/>
</Host>

Make sure you replace server1.example.com with your details in all the places.

Now lets create a Catalina folder for our new domain:
mkdir /etc/tomcat6/Catalina/server1.example.com
And copy the original context files to new domain:
cp /etc/tomcat6/Catalina/localhost/* /etc/tomcat6/Catalina/server1.example.com/
But remove the ROOT.xml file, because we don't need that one on our new domain:
rm -f /etc/tomcat6/Catalina/server1.example.com/ROOT.xml
 4.5 Create a test file and test our new setup
Create a new test.jsp file for our new virtual host:
nano /var/www/server1.example.com/htdocs/test.jsp
and add:
<html>

    <head>
        <title>Hello World</title>
    </head>
    <body>
        <h1>Hello World</h1>
        Today is: <%= new java.util.Date().toString() %>
    </body>
</html>
Save and exit the file.
Finally restart the services, so that the new configuration will load:
/etc/init.d/apache2 stop
/etc/init.d/tomcat6 restart
/etc/init.d/apache2 start
Then use your browser to visit http://server1.example.com/test.jsp and verify that you get the test page we just created.
 
You should also be able to visit http://server1.example.com/examples which is now also available on our virtual host (/docs, /manager/html and /host-manager/html should also work):

Your done!
 
Src: http://www.how2forge.org/how-to-install-tomcat6-with-sun-java-and-apache2-integration-on-ubuntu-10.04-lucid-lynx-with-virtual-hosts-p2
Administrations Configurations (Linux)

Post navigation

Previous post
Next post

Leave a Reply Cancel reply

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

Myself…

Hi, I am Hasan T. Emdad Rumi, an IT Project Manager & Consultant, Virtualization & Cloud Savvyfrom Dhaka, Bangladesh. I have prior experience in managing numerous local and international projects in the area of Telco VAS & NMC, National Data Center & PKI Naitonal Root and CA Infrastructure. Also engaged with several Offshore Software Development Team.

Worked with Orascom Telecom-Banglalink, Network Elites as VAS partner, BTRC, BTT (Turkey) , Mango Teleservices Limited and Access to Informaiton (A2I-UNDP)

Currently working at Oracle Corporation as Principal Technology Solution and Cloud Architect.

You can reach me [h.t.emdad at gmail.com] and I will be delighted to exchange my views.

Tags

Apache Bind Cacti CentOS CentOS 6 CentOS 7 Debain Debian Debian 10 Debian 11 Debian 12 DKIM Docker endian icinga iptables Jitsi LAMP Letsencrypt Linux Munin MySQL Nagios Nextcloud NFS nginx pfsense php Postfix powerdns Proxmox RDP squid SSH SSL Ubuntu Ubuntu 16 Ubuntu 18 Ubuntu 20 Varnish virtualbox vpn Webmin XCP-NG zimbra

Topics

Recent Posts

  • Install Jitsi on Ubuntu 22.04 / 22.10 April 30, 2025
  • Key Lessons in life April 26, 2025
  • Create Proxmox Backup Server (PBS) on Debian 12 April 19, 2025
  • Add Physical Drive in Proxmox VM Guest April 19, 2025
  • Mount a drive permanently with fstab in Linux April 16, 2025
  • Proxmox 1:1 NAT routing March 30, 2025
  • Installation steps of WSL – Windows Subsystem for Linux March 8, 2025
  • Enabling Nested Virtualization In Proxmox March 8, 2025
  • How to Modify/Change console/SSH login banner for Proxmox Virtual Environment (Proxmox VE / PVE) March 3, 2025
  • Install Proxmox Backup Server on Debian 12 February 12, 2025

Archives

Top Posts & Pages

  • Install Jitsi on Ubuntu 22.04 / 22.10
©2025 Bots! | WordPress Theme by SuperbThemes