How to Install Apache Tomcat 10 on Ubuntu 21

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Apache Tomcat is an open-source Java servlet and Java Server Page container. Developers build and deploy dynamic java-based applications using Apache Tomcat. Java servlets are small java programs defining how a server handles requests and responses. Developers write the servlets while Tomcat handles all the backend and routing. As it is an opensource tool, Apache Tomcat is contributed by developers all over the world.

Apache Tomcat is an open-source Java HTTP web server developed by the Apache Software Foundation. Tomcat helps to deploy the Java Servlet and the JavaServer Pages and serves them like an HTTP web server.

In this guide we will install Apache Tomcat 10 on Ubuntu 21.

Install JDK Ubuntu linux system.

apt update
apt install default-jdk

Check java version with the following command:

java -version

Download Apache Tomcat archive.

apt install wget
wget https://downloads.apache.org/tomcat/tomcat-10/v10.0.12/bin/apache-tomcat-10.0.12.tar.gz

Extract the tar file.

tar -xvzf apache-tomcat-10.0.12.tar.gz

Move extracted file to /usr/share directory.

mv apache-tomcat-10.0.12/ /usr/share/apache-tomcat

Create apache tomcat user because we will use this user. Also give permissions to user tomcat.

useradd -M -d /usr/share/apache-tomcat tomcat
chown -R tomcat /usr/share/apache-tomcat

Allow access to Apache Tomcat UI from your IP.

nano /usr/share/apache-tomcat/webapps/manager/META-INF/context.xml

Add your IP in this file.

Do the same with the following file:

nano /usr/share/apache-tomcat/webapps/host-manager/META-INF/context.xml

Save and quit both files after adding IP.

Now secure access to admin UI. Edit the following file:

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

Add following lines before context </tomcat-users>:

<!-- manager section user role -->
<role rolename="manager-gui" />
<user username="manager" password="Passw0rd" roles="manager-gui" />

<!-- admin section user role -->
<role rolename="admin-gui" />
<user username="admin" password="Strong123" roles="manager-gui,admin-gui" />

save and exit the file.

Create systemd unit for tomcat to start / stop and restart service.

nano /etc/systemd/system/tomcat.service

Paste following lines:

[Unit]
Description=Tomcat
After=syslog.target network.target

[Service]
Type=forking

User=tomcat
Group=tomcat

Environment=JAVA_HOME=/usr/lib/jvm/default-java
Environment='JAVA_OPTS=-Djava.awt.headless=true'

Environment=CATALINA_HOME=/usr/share/apache-tomcat
Environment=CATALINA_BASE=/usr/share/apache-tomcat
Environment=CATALINA_PID=/usr/share/apache-tomcat/temp/tomcat.pid

ExecStart=/usr/share/apache-tomcat/bin/catalina.sh start
ExecStop=/usr/share/apache-tomcat/bin/catalina.sh stop

[Install]
WantedBy=multi-user.target

Save and Exit.

Reload system daemon and start Tomcat Service.

systemctl daemon-reload
systemctl restart tomcat
systemctl enable tomcat
systemctl status tomcat
ufw allow 8080

Now open your web browser and type https://yourIP:8080. You will see the default tomcat page. You can use it as per your need.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Mel
Melhttps://unixcop.com
Unix/Linux Guru and FOSS supporter

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook