Tomcat server setup

What is Tomcat?

Apache Tomcat is an open-source software used to host java web applications.

Pre-requisites to install tomcat?

Java should be installed before installing tomcat on a machine. To install java jdk in Debian-based Linux systems use the below command as per the java version.

sudo apt install openjdk-11-jdk

To verify the java installation run

java -version

If you successfully get a similar output then java is installed.

How to install the Tomcat server?

Download the archive as per the latest or required version using the following command

wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.6/bin/apache-tomcat-10.1.6.tar.gz

Extract the contents of the downloaded archive

sudo tar xzvf apache-tomcat-10*tar.gz -C /opt/tomcat --strip-components=1

Configure users

To access the tomcat server as manager, admin, and deployer we need to define in the tomcat-users.xml present in the conf folder.

sudo vim /opt/tomcat/conf/tomcat-users.xml

Add the below lines

<role rolename="manager-gui" />
<role rolename="manager-script" />
<role rolename="manager-jmx" />
<role rolename="manager-status" />
<role rolename="admin-gui" />

<user username="manager" password="Test@123" roles="manager-gui" />
<user username="admin" password="Test@123" roles="manager-gui,admin-gui,manager-script,manager-status,manager-jmx" />
<user username="deployer" password="Test@123" roles="manager-script" />

Create soft link

To create a soft link for startup.sh and shutdown.sh, you can use the below commands.

Change port

To change the server running on default port 8080, we can edit the port defined in /opt/tomcat/conf/server.xml

Access manager page

By default, the manager page access is restricted from other IPs except the server IP where tomcat is installed. To modify the access comment the below lines in the context.xml

Restart services

You can use the soft link created earlier to restart the tomcat services.

tomcat-stop

tomcat-start

Access tomcat

Use the public IP with a port to access the tomcat server

Now you can log in using the earlier defined user in tomcat-users.xml and upon successful login, the screen below screen should be displayed.

And with this, we have successfully set up our tomcat server.