How to install Apache Tomcat 7.0.26 on Ubuntu Linux 12.04 LTS

Abstract

Apache Tomcat is a web container that allows you to serve Java Servlets and JSP (Java Server Pages) web applications. This blog entry will guide you through the step-by-step installation of Apache Tomcat 7.0.26 on Ubuntu Linux 12.04 LTS 32 bit.

This installation was performed on a clean installation of Ubuntu Server 12.04 LTS

Java

Before you install Tomcat, you need to install Java. The standard tomcat7 package includes the OpenJDK distribution of Java. I have opted not to go the OpenJDK route due to numerous software products that I use that are not yet certified on the OpenJDK platform. I recommend installing the official Oracle JDK distribution instead.

Follow the instructions in How to Install Oracle Java 6 update 37 on Ubuntu 12.04 Linux to install Oracle Java.

Tomcat

I have seen several blog entries that simply extract the Tomcat binaries downloaded from the Apache website and run the start-up script. When you simply extract the Tomcat binary distribution, all the Tomcat files are extracted to one top-level directory. I prefer installing Tomcat using the apt-get command, it saves time and places all the Tomcat files in the correct folders for you.

For more information on what actually happens during the apt-get install process, refer to the official Ubuntu package website for tomcat7. On the same package page, you will find a link to the directory locations where the tomcat7 files installed to.

Step 1: Install the Oracle Java 6 update 37, if you have not done so already

Follow the instructions in How to Install Oracle Java 6 update 37 on Ubuntu 12.04 Linux

Step 2: Install the tomcat7 package

During this step, Tomcat and OpenJDK will be installed. We will configure Tomcat in a later step to use the Oracle JDK instead.

Run the following commands in your console:

sudo apt-get update
sudo apt-get install tomcat7

Step 3: Stop the tomcat7 service

Run the following command in your console to stop the tomcat7 service:

sudo service tomcat7 stop

Response:

Stopping Tomcat servlet engine tomcat7 [ OK ]

Step 4: Edit the tomcat7 default start-up configuration file

This step assumes that you installed Java as detailed in Step 1. If you are using another version of Java adjust JAVA_HOME accordingly.

Run the following command in your console to edit JAVA_HOME in the default tomcat7 start-up configuration file:

sudo nano /etc/default/tomcat7

Change the JAVA_HOME option to the following and remove the starting #:

JAVA_HOME=/usr/lib/jvm/jdk1.6.0_37

Save the file and you are done. Tomcat will now start using the Oracle JDK instead of the OpenJDK.

Step 5: Start the tomcat7 service

Run the following command in your console to start the tomcat7 service:

sudo service tomcat7 start

Step 6: Ensure that you are running on the Oracle JDK

Run the following command in your console:

/usr/share/tomcat7/bin/version.sh

Step 7: Open the default tomcat port in your firewall

Opening a port is optional and you only need to run this command if you have a firewall enabled and want to access Tomcat for a different host:

sudo ufw enable 8080/tcp

Step 8: Test your installation

Navigate your browser to http://localhost:8080. If you see “It works!”, the installation was successful.

You can also use the wget command to test your installation. This will create an index.html file in the current folder, if the installation was successful.

wget localhost:8080

Step 9: Congratulations – You have just installed Tomcat on Ubuntu. Share this fantastic news using one of the share buttons or leave a comment in the reply section below.

TwitterFacebookLinkedInGoogle+tumblrStumbleUponEmail

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>