Installing Apache Tomcat on Ubuntu 14.04

Apache Tomcat, created by the same organization as the popular Apache web server, is a web server that allows you to serve Java webpages to visitors. In this guide, we’ll see how we can install Apache Tomcat on an Ubuntu 14.04 server.

Step 1: Installing prerequisites #

First off, we need to update all software on our server and install a number of prerequisites:

apt-get update

After you’ve done that, install the JDK:

apt-get install default-jdk

Step 2: Creating the user #

We will need a non-root user to run the Tomcat web server under. For easy management, we’ll call it “tomcat”. Naturally, this can be anything you want.

groupadd tomcat
useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat

Step 3: Installing Tomcat #

After confirming that the prerequisites have successfully been installed, we can begin the Tomcat installation process. First, we’re going to download the files:

mkdir /opt/tomcat
tar xvf apache-tomcat-8*tar.gz -C /opt/tomcat --strip-components=1

Set the permissions:

cd /opt/tomcat
sudo chgrp -R tomcat conf
sudo chmod g+rwx conf
sudo chmod g+r conf/*
sudo chown -R tomcat work/ temp/ logs/

Step 3: Creating the script #

We will now need to create a script in order to run Tomcat as a service.

In order to do this, you will need to set the JAVA_HOME variable. You can find that using the following command:

update-alternatives --config java

After doing that, create the script:

vi /etc/init/tomcat.conf

Paste the following contents into the file:

description "Tomcat"

  start on runlevel [2345]
  stop on runlevel [!2345]
  respawn limit 10 5

  setuid tomcat
  setgid tomcat

  env JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre
  env HOME=/opt/tomcat

  # Modify these options as needed
  env JAVA_OPTS="-Djava.awt.headless=true"
  env MEMORY="-Xms512M -Xmx1024M -server -XX:+UseParallelGC"

  exec $HOME/bin/ run

  # cleanup temp directory after stop
  post-stop script
    rm -rf $HOME/temp/*
  end script

After saving this file, execute:

sudo initctl reload-configuration

You can now start the Tomcat web server using the following command:

initctl start tomcat

After starting the service, you can access Tomcat at the following URL:


Step 4: Setup the Web Management Interface #

In order to access the Web Management Interface, we will need to create a user that will be able to access it. Open the following file with your favorite editor:


Paste the following into this file:

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

Change “user” to the username and “password” to the password for the user you want to create. Make sure to remember it!

Restart Tomcat by typing:

initctl restart tomcat

You will now be able to log in with the username and password you have just created.

You can access Tomcat at the following URL:


There are multiple interfaces. You can access the Manager App here:


With the Manager App, you can manage websites hosted on your Tomcat server.

The Host Manager can be accessed from the following URL:


Congratulations! You have now setup your own Tomcat server!

Powered by BetterDocs