Skip to content
jakob-grabner edited this page Oct 13, 2015 · 1 revision

Tomcat installation guide

Based on this.

Install Apache Tomcat

In this guide, we will install Tomcat version 7 and its associated packages.

To get the basic package, we can update our package source list and then install the main package:

sudo apt-get update
sudo apt-get install tomcat7

This is all we need to do to get to the default Tomcat page. Our installation is not complete yet, but you can take a look at the default Tomcat page by going to your IP address or domain followed by :8080 in your web browser:

your_domain_or_ip:8080

It works!

Directories

Logging

/var/log/tomcat7/

Most important is the catalina.out

Configuration

Main configuration folder /etc/tomcat7

Java options and startup config: /etc/defaults/tomcat7

Tomcat_Home Here are your web apps! /var/lib/tomcat7

Another config dir /usr/share/tomcat6

Change default port

Tomcat listens per default on port 8080. If you want to it to listen to another port go to:

nano /etc/tomcat7/server.xml

Then find the connector and change the specified port. For example we now change it to 8888:

<Connector port="8888" protocol="HTTP/1.1"
           connectionTimeout="20000"
           URIEncoding="UTF-8"
           redirectPort="8443" />

Digital Ocean Fix

If you are using a debian VM hosted on digital ocean like me, you might stumble over an annoying bug. If tomcat is not available after a few seconds and the catalina.out hangs at:

Oct 12, 2015 10:17:53 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /var/lib/tomcat7/webapps/ROOT

To fix it add this line to /etc/default/tomcat7

Digital ocean fix

JAVA_OPTS="${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom"

Install tomcat7-admin

In order to take advantage of more of Tomcat's features, we will install some additional Tomcat packages. These will allow us to use a web interface to control Tomcat.

sudo apt-get install tomcat7-admin

Install Java Development Tools (if not available)

In order to use Tomcat to develop Java applications on your server, you will need to download and install a few things.

The first thing we need to do is install a compatible Java Development Kit. We can install the one that Debian selected as default with the following command:

sudo apt-get install default-jdk

Configure Tomcat Web Interface

and password. Tomcat does not do this by default for security reasons.

The configuration is very simple. We need to edit a file called tomcat-users.xml. Open it with an editor like this:

sudo nano /etc/tomcat7/tomcat-users.xml

Inside, you will find a heavily commented user configuration file. In fact, the only portions of the file that are not comments are:

<tomcat-users>
</tomcat-users>

As you might expect, we need to define a user between these two lines. We will give this user access to the web interfaces. We can define a user like this:

<tomcat-users>
    <user username="admin" password="password" roles="manager-gui,admin-gui"/>
</tomcat-users>

Choose whatever username and password you would like. This will provide you with login credentials that allow you to access the management panels.

Save and close the file when you are finished.

We should restart Tomcat in order to implement our changes:

sudo service tomcat7 restart

Now the manager gui should be running, test it under:

your_domain_or_ip:8080/manager/

#Remote debugging adjustments (For Intellij)

Add these lines to /etc/default/tomcat7

For intellij: JMX support

JAVA_OPTS="${JAVA_OPTS} -Dcom.sun.management.jmxremote=" JAVA_OPTS="${JAVA_OPTS} -Dcom.sun.management.jmxremote.port=1099" JAVA_OPTS="${JAVA_OPTS} -Dcom.sun.management.jmxremote.ssl=false" JAVA_OPTS="${JAVA_OPTS} -Dcom.sun.management.jmxremote.authenticate=false" JAVA_OPTS="${JAVA_OPTS} -Djava.rmi.server.hostname="