Knowledgebase

How To Install Apache Tomcat 7 on CentOS 7 ?

sudo yum install tomcat -y

This will install Tomcat 7 and its dependencies, such as Java, and it will also create the tomcat user.

 

sudo vi /usr/share/tomcat/conf/tomcat.conf

we will install a few additional packages that will help you manage your Tomcat applications and virtual hosts.

Make change to the Java options that Tomcat uses when it starts. Open the Tomcat configuration file.

sudo vi /usr/share/tomcat/conf/tomcat.conf

Add the following JAVA_OPTS line to the file. Feel free to change the Xmx and MaxPermSize values—these settings affect how much memory Tomcat will use

JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom -Djava.awt.headless=true -Xmx512m -XX:MaxPermSize=256m -XX:+UseConcMarkSweepGC"

Save and exit.

Install Admin Packages

To install the default Tomcat root page (tomcat-webapps), and the Tomcat Web Application Manager and Virtual Host Manager (tomcat-admin-webapps), run this command

sudo yum install -y tomcat-webapps tomcat-admin-webapps

This adds the ROOTexamplessamplemanager, and host-manager web apps to the tomcat/webapps directory.

 

Configure Tomcat Web Management Interface

In order to use the manager webapp installed in the previous step, we must add a login to our Tomcat server. We will do this by editing the tomcat-users.xml file.

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

 

This file is filled with comments which describe how to configure the file. You may want to delete all the comments between the following lines, or you may leave them if you want to reference the examples.

<tomcat-users>
...
</tomcat-users>


Add a user who can access the manager-gui and admin-gui (the management interface that we installed earlier).
You can do so by defining a user similar to the example below. Be sure to change the username and password to something secure.

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


Save and exit the tomcat-users.xml file.


Start Tomcat

sudo systemctl start tomcat

If you started the service earlier for some reason, run the restart command instead.

sudo systemctl restart tomcat

sudo systemctl enable tomcat

 

Access the Web Interface

Open in web browser:
http://server_IP_address:8080


You will see something like the following image.

tomcat

Let’s take a look at the Manager App, accessible via the link or http://server_IP_address:8080/manager/html

tomcat-manager


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 apps (i.e. find memory leaks).

http://server_IP_address:8080/host-manager/html

tomcat-virtual-host-manager


From the Virtual Host Manager page, you can add virtual hosts to serve your applications from.