Learn how to install and use Apache Tomcat on CentOS 7. Apache Tomcat is a Java Servlet container developed by Apache which allows you to deploy Java servlets and JSPs. Apache Tomcat also functions as a web server, which is able to support small to medium-sized websites.

This tutorial also covers how to install and use the Tomcat Web Admin Manager, which allows you to manage Tomcat and virtual hosts from a web browser.

Re­quire­ments

  • A Cloud Server running Linux (CentOS 7)
  • If you have a firewall, you will need to allow access to port 8080.
VPS Hosting
VPS hosting at un­beat­able prices on Dell En­ter­prise Servers
  • 1 Gbit/s bandwidth & unlimited traffic
  • Minimum 99.99% uptime & ISO-certified data centres
  • 24/7 premium support with a personal con­sult­ant

Install Tomcat

In­stalling Tomcat on CentOS 7 requires one simple command:

sudo yum install tomcat

This will install Tomcat and its de­pend­en­cies, including Java.

There are several ad­di­tion­al packages which many users, par­tic­u­larly those who are new to Tomcat, will find useful. Install them with the command:

sudo yum install tomcat-webapps tomcat-admin-webapps tomcat-docs-webapp tomcat-javadoc

This will install:

  • The Tomcat root webpage (tomcat-webapps)
  • The Tomcat Web Admin Manager (tomcat-admin-webapps)
  • The official online Tomcat doc­u­ment­a­tion (tomcat-docs-webapp and tomcat-javadoc)

If your server is running Apache, stop it with the command:

sudo systemctl stop httpd

Start Tomcat with the command:

sudo systemctl start tomcat

And enable Tomcat to auto­mat­ic­ally start if the server is rebooted:

sudo systemctl enable tomcat

You can verify that Tomcat is running by visiting the URL http://example.com:8080 in a web browser. You will see the Tomcat welcome page, which includes links to the Tomcat doc­u­ment­a­tion which you installed in the previous step.

Use the Tomcat Web Admin Manager

In order to use Tomcat's web man­age­ment interface, you will need to create a user. Open the tomcat-users.xml file with the command:

sudo nano /usr/share/tomcat/conf/tomcat-users.xml

Scroll down to below the line which reads <tomcat-users> and add the in­form­a­tion for your user account:

<user username="[username]" password="[password]" roles="manager-gui,admin-gui"/>

For example, to add the user jdoe with password En4EW25eI0 this section will read:

<tomcat-users>
<user username="jdoe" password="En4EW25eI0" roles="manager-gui,admin-gui"/>

Save and exit the file. Restart the Tomcat service for the changes to take effect:

sudo systemctl restart tomcat

In a browser, visit the URL http://example.com:8080 to see the Tomcat welcome page. Click the Manager App link.

You will be prompted to log in with the username and password you created.

From this page you can stop, reload, and run dia­gnostics on various Java ap­plic­a­tions.

Dedicated Server
Per­form­ance through in­nov­a­tion
  • En­ter­prise hardware
  • Con­fig­ur­able hardware equipment
  • ISO-certified data centres

Manage Virtual Hosts

To manage virtual hosts through the Web Ap­plic­a­tion Manager, scroll down and click the /host-manager link.

This will take you to the Tomcat Virtual Host Manager, where you can add and manage virtual hosts to your Tomcat server.

Go to Main Menu