Tomcat is a servlet container developed by the Jakarta project under the Apache Software Foundation. According to the technical specifications provided by Sun Microsystems, Tomcat implements support for Servlet and JavaServer Page (JSP), and provides some unique functions as a Web server, such as Tomcat management and control platform, security domain management and Tomcat valve, etc. Since Tomcat itself also includes an HTTPserver , it can also be regarded as a separate Web server . If you develop Java applications, Tomcat is a quick and easy way to serve them in a complete server environment designed specifically for this purpose.
In this tutorial, we will install Tomcat and do some basic configuration on a Debian 7 VPS .To complete this tutorial, you must have a normal user with sudo privileges.
In this tutorial, we will install Tomcat and its related packages. These are included in the default Debian repositories.
To get the base repository, we can update the sources list and then install the package:
sudo apt-get update
sudo apt-get install tomcat7
That's all we need to do to get to the default Tomcat page. Our installation is not complete, but you can log in to your server's
8080 port to view the default Tomcat page in your browser:
To take advantage of more of Tomcat's capabilities, we'll install some additional Tomcat packages.
These will allow us to control Tomcat using the web interface. It will install some documentation and examples, which we can also view through the website interface.
sudo apt-get install tomcat7-admin tomcat7-examples tomcat7-docs
## Install Java Development Tools
In order to develop Java applications on your server using Tomcat, you need to download and install a few things.
The first thing we need to do is install a compatible Java Development Kit. We can install it with the following command:
sudo apt-get install default-jdk
The version installed here is
openjdk-6-jdk , at present, this version is the most stable version running on Debian
The Tomcat documentation also recommends that you install Apache Ant, a build tool for Java applications. The Tomcat documentation also recommends that you install a version control system, here we recommend installing git:
sudo apt-get install ant git
## Configure the Tomcat website
Before we can start using some of the features we installed, we need to configure our server with a user and password.
Configuration is very simple. We need to edit a file called tomcat-users.xml. Open it with an editor:
sudo nano /etc/tomcat7/tomcat-users.xml
Inside, you'll find a bunch of annotation configuration files. In fact, the only uncommented part of the file is:
We need to define the user between these two lines. We will grant this user access to the web interface. The configuration is as follows:
<user username="admin" password="password" roles="manager-gui,admin-gui"/>
Set username and password. Save and close the file when done.
Restart Tomcat to implement the changes:
sudo service tomcat7 restart
## Test the website interface
Once Tomcat is installed and user login is configured, the main page can be accessed by going to the server IP address or domain name ending in :8080 as follows:
You will see the same default Tomcat page you saw before:
However, since we have already installed and configured the components, we have access to more functionality. You can access the Tomcat documentation in your browser by clicking the link shown on the page or by visiting this page:
When you have questions about how to do something with Tomcat, check out the Q&A on this page.
We also now have access to some different sample programs. These can be accessed via links on the same initial login page, or by visiting:
Clicking on these items gives us an idea of how the different functions are implemented in this environment. The main functions you want to access are the manager webapp and the host-manager webapp .
Again, you can access these from the initial login page, or visit:
You can manage Java applications at the first site. It allows you to easily start, stop, deploy and reload your application. It can also find the cause of memory leaks caused by running applications:
In another page, you can test, tune, and add virtual hosts to serve your application. This allows you to easily set up access to deployed applications:
Tomcat provides an excellent platform for controlling and serving Java applications in a website environment. You can easily deploy .war files and have them up and running in a fraction of the time. Did you learn it? Buy a CVM and try it out!