How to install Tomcat on Tencent Cloud CVM
Tags: tencentcloud, tomcat
Published: 2022-07-15 03:18:07

## **introduce**

**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 [HTTP](https://zh.wikipedia.org/wiki/HTTP)[server](https://zh.wikipedia.org/wiki/%E6%9C%8D%E5%8A%A1%E5%99%A8) , it can also be regarded as a separate [Web server](https://zh.wikipedia.org/wiki/Web%E6%9C%8D%E5%8A%A1%E5%99%A8) . 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 .](https://www.tencentcloud.com/products/cvm?from_social=dev_1)To complete this tutorial, you must have a normal user with sudo privileges.
## **Install Apache Tomcat**

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:

```
your_domain_or_ip:8080
```

[![undefined](https://cdn.computeinit.com/wp-content/uploads/2021/05/ccad705958b857b9dc2459f3eb87f409.png?imageMogr2/format/webp)](https://cdn.computeinit.com/wp-content/uploads/2021/05/ccad705958b857b9dc2459f3eb87f409.png)

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:

```
<tomcat-users>
</tomcat-users>
```
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:

```
<tomcat-users>
    <user username="admin" password="password" roles="manager-gui,admin-gui"/>
</tomcat-users>
```
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:
 ```
 your_domain_or_ip:8080
 ``` 
 You will see the same default Tomcat page you saw before:
[![undefined](https://cdn.computeinit.com/wp-content/uploads/2021/05/67b1b29c5e81dbfd8d48ac2223ef97b5.png?imageMogr2/format/webp)](https://cdn.computeinit.com/wp-content/uploads/2021/05/67b1b29c5e81dbfd8d48ac2223ef97b5.png)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:

```
your_domain_or_ip:8080/docs


When you have questions about how to do something with Tomcat, check out the Q&amp;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:
your_domain_or_ip:8080/examples
```
[![undefined](https://cdn.computeinit.com/wp-content/uploads/2021/05/6b3f35ef0228f46249a8a775ebc1fd0c.png?imageMogr2/format/webp)](https://cdn.computeinit.com/wp-content/uploads/2021/05/6b3f35ef0228f46249a8a775ebc1fd0c.png)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:
 ```
 your_domain_or_ip:8080/manager/html
 ``` 
 and:
 ```
 your_domain_or_ip:8080/host-manager/html
 ``` 
 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:
[![undefined](https://cdn.computeinit.com/wp-content/uploads/2021/05/bf5f8b1cdbdab6f0601394bc6b28c004.png?imageMogr2/format/webp)](https://cdn.computeinit.com/wp-content/uploads/2021/05/bf5f8b1cdbdab6f0601394bc6b28c004.png)
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:
[![undefined](https://cdn.computeinit.com/wp-content/uploads/2021/05/dcf4fd087b277a86c8a81e630c489512.png?imageMogr2/format/webp)](https://cdn.computeinit.com/wp-content/uploads/2021/05/dcf4fd087b277a86c8a81e630c489512.png)
## **in conclusion**

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](https://www.tencentcloud.com/products/cvm?from_social=dev_1) and try it out!