If you are unaware, Apache tomcat is an application server that is used to serve java applications to the web. Tomcat is an open source implementation of the java servlet and javaServer pages technologies, it is released by the Apache software foundation.
This post basically covers the installation and some configuration of Tomcat 7.0.x, the latest stable version at the time of posting on your Ubuntu 14.04 VPS.
We are going to install Tomcat on Ubuntu using the apt-get, the simplest method. This method will install the latest release of Tomcat that is found in the Ubuntu repositories.
Step One — basics
Before you begin, you should ensure you have a separate non-root user account set up on your server. We will be using the demo user created here for the rest of this tutorial.
Step Two – Install Tomcat
First update your apt-get package lists:
sudo apt-get update
Then run the following command to begin the installation:
sudo apt-get install tomcat7
At the prompt to install answer yes. This will install tomcat and its dependancies like java, create the tomcat7 user and start tomcat with its default settings. At this moment tomcat is not yet completely installed, though the default pagecan be accessed by going to your domain or IP address followed by .8080 ina web browser:
http://your_ip_address:8080
A splash page will appear that say “it works”. We now go deeper in the installation of tomcat.
Step Three – Installing Additional Packages
This section is useful for those who are getting into Tomcat for the first time.
The command below will install the Tomcat online documentation, the web interface (manager webapp) and some webapps.
sudo apt-get install tomcat7-docs tomcat7-admin tomcat7-examples
Answer yes at the prompt to install these packages.
Step Four – Install Java Development Kit (Optional)
This will be useful to those planning to develop apps on their server be sure to install the software in this section. The Java Development Kit (JDK) enables development of Java applications to run in the Tomcat server. Running the following command will install openjdk-7-jdk:
sudo apt-get install default-jdk
The Tomcat documentation suggests also installing Apache Ant, which is used to build Java applications, and a source control system, such as git .we will install both of those with the following command:
sudo apt-get install ant git
Step 5 – Configure Tomcat Web Management Interface
We have to add login to our tomcat in order to use manager webapp. This is done by editing the tomcat-users.xml file
sudo nano /etc/tomcat7/tomcat-users.xml
You can delete the comments between these two lines if you don’t want to keep them for reference:
<tomcat-users>
</tomcat-users>
You can add a user who can access the manager-gui and admin-gui (the management interface that we installed in Step Three).this can be done by defining a user similar to the example below. You can change the password and username if you want to.
<tomcat-users>
<user username=”admin” password=”password” roles=”manager-gui,admin-gui”/>
</tomcat-users>
Save and quit to put the changes into effect, restart the tomcat service.
sudo service tomcat7 restart
Step 6 – Access the Web Interface
Now access the web management interface in a web browser:
http://your_ip_address:8080
if successful you will see an image with the words “ it works!” in bold.
There are four links to packages you installed in step three:
- Tomcat7-docs: Online documentation for Tomcat. Accessible via http://your_ip_address:8080/docs/
- Tomcat7-examples: Tomcat 7 Servlet and JSP examples. By clicking through the example webapps you can get a basic idea of how they work (and also look at the source code to see how they were implemented). Accessible via http://your_ip_address:8080/examples/
- Tomcat7-admin (manager-webapp): Tomcat Web Application Manager. This will allow you to manage and your Java applications.
- tomcat7-admin (host-manager): Tomcat Virtual Host Manager.
Web Application Manager, accessible via the link or http://your_ip_address:8080/manager/html:
The Web Application Manager is used to manage your Java applications. You can Start Stop, Reload, Deploy, and Undeploy here. You can also run some diagnostics on your app.
Virtual Host Manager, accessible via the link or http://your_ip_address:8080/host-manager/html/:
From the Virtual Host Manager page, you can add virtual hosts to serve your applications.
You are now done.