Article

Table of Contents
Theme:
Was this article helpful?
Try Vultr Today with

$50 Free on Us!

Want to contribute?

You could earn up to $600 by adding new articles.

Installing Apache Tomcat on Ubuntu 14.04

Last Updated: Fri, Oct 9, 2015
Java Ubuntu Web Servers
Archived content

This article is outdated and may not work correctly for current operating systems or software.

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:

cd

wget http://mirror.sdunix.com/apache/tomcat/tomcat-8/v8.0.23/bin/apache-tomcat-8.0.23.tar.gz

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

  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 -Djava.security.egd=file:/dev/./urandom"

  env MEMORY="-Xms512M -Xmx1024M -server -XX:+UseParallelGC"



  exec $HOME/bin/catalina.sh 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:

serverip:8080

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:

/opt/tomcat/conf/tomcat-users.xml

Paste the following into this file:

<tomcat-users>

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

</tomcat-users>

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:

serverip:8080

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

serverip:8080/manager/html

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

The Host Manager can be accessed from the following URL:

serverip:8080/host-manager/html/

Congratulations! You have now setup your own Tomcat server!

Want to contribute?

You could earn up to $600 by adding new articles.