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.
First off, we need to update all software on our server and install a number of prerequisites:
After you've done that, install the JDK:
apt-get install default-jdk
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
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/
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:
Paste the following contents into the file:
description "Tomcat" start on runlevel  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:
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:
<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:
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!