Apache Tomcat is a open source, freeware, and used for Java-based web applications. Developers use it to implement Java Servlet and JavaServer Pages technologies.
This tutorial in covers basic installation and configuration of Tomcat 9 on your Ubuntu 20.04 server.
Step 1 : Install Java
First install update package and after Java Development Kit package installed.
sudo apt-get update
sudo apt-get install default-jdk
After check
java --version
Step 2: Create Tomcat User and Group
Create a new group and system user to run the Apache Tomcat service from the /opt/tomcat directory.
sudo groupadd tomcat
sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat
Step 3: Download Tomcat 9
cd /opt
sudo wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.56/bin/apache-tomcat-9.0.56.tar.gz
sudo tar xzvf apache-tomcat-9*tar.gz
sudo mv -r apache-tomcat-9.0.56 tomcat
Step 4: Update Permissions
sudo chgrp -R tomcat /opt/tomcat
chmod 755 /opt/tomcat
sudo chown -R tomcat webapps/ work temp/ logs
Step 5: Create a systemd Service File
sudo update-java-alternatives -l
we can create the systemd service file name tomcat.service in the /etc/systemd/system directory in typing:
sudo nano /etc/systemd/system/tomcat.service
When you are finished, save and close the file. After reload the systemd daemon.
sudo systemctl daemon-reload
sudo systemctl start tomcat
sudo systemctl status tomcat
Step 6: Adjust the Firewall and Test the Tomcat Server
sudo ufw allow 8080
Open in web browser
http://server_domain_or_IP:8080
sudo systemctl enable tomcat
Step 7: Configure Tomcat Web Management Interface
Configuration file tomcat-users.xml file in add username and password add.
sudo nano /opt/tomcat/latest/conf/tomcat-users.xml
This file add in tomcat-users.xml file
<tomcat-users>
<! --
Comments
-- >
<role rolename="admin-gui"/>
<role rolename="manager-gui"/>
<user username="admin" password="Your_Password" roles="admin-gui, manager-gui"/>
</tomcat-users>
Step 8 : Configure Remote Access
1. First, open the manager file:
sudo nano /opt/tomcat/latest/webapps/manager/META-INF/context.xml
This file add in context.xml file
<Context antiResourceLocking="false" privileged="true">
<! --
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+.d+|::1|0000:1" />
-- >
</Context>
sudo systemctl restart tomcat
0 Comments