Learn how to – Install Apache Tomcat 10 on Ubuntu 22.04|20.04|18.04.
The objective of this guide is to help install and configure Apache Tomcat 10.x on Ubuntu 22.04|20.04|18.04 Linux server. Apache Tomcat is an open source implementation of the Java Servlet, JavaServer Pages, Java Expression Language and Java WebSocket technologies. Tomcat is a platform-independent tool and runs where Java is installed.
You need access to Ubuntu shell as a user with sudo permissions. We’ll perform an installation of Java before we download Apache Tomcat 10 on Ubuntu 22.04/20.04/18.04. Without much theory let’s proceed to install and configure Java Development Kit / OpenJDK on Ubuntu
Step 1: Install Java Runtime
For this guide, we will install Oracle Java JDK Ubuntu Linux system. You can perform the installation from PPA repository like ppa:webupd8team/java or install OpenJDK edition.
sudo apt update
sudo apt install default-jdk
Hit the y key in your keyboard to continue with the installation:
0 upgraded, 95 newly installed, 0 to remove and 146 not upgraded.
Need to get 303 MB of archives.
After this operation, 837 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Confirm installation by checking the Java version:
$ java --version
openjdk 11.0.15 2022-04-19
OpenJDK Runtime Environment (build 11.0.15+10-Ubuntu-0ubuntu0.22.04.1)
OpenJDK 64-Bit Server VM (build 11.0.15+10-Ubuntu-0ubuntu0.22.04.1, mixed mode, sharing)
Step 2: Install Apache Tomcat 10 Server
Now that we have Java Open JDK installed, we should be ready to start the installation of Apache Tomcat on Ubuntu 22.04/20.04/18.04. The installation process is as below:
Download Apache Tomcat archive
Let’s download Apache tomcat 10 using wget. You can see latest Tomcat 10 releases from downloads page.
sudo apt install wget
VER="10.1.1"
wget https://archive.apache.org/dist/tomcat/tomcat-10/v${VER}/bin/apache-tomcat-${VER}.tar.gz
Extract tar archive and install Tomcat
After the download extract the archive file:
tar xvf apache-tomcat-${VER}.tar.gz
Move extracted files to /usr
sudo mv apache-tomcat-${VER} /usr/share/apache-tomcat
Create apache tomcat user:
sudo useradd -M -d /usr/share/apache-tomcat tomcat
sudo chown -R tomcat /usr/share/apache-tomcat
Step 3: Configure Apache Tomcat 10 Server
Allow access to Apache Tomcat UI from trusted network/Ip:
Edit the files:
sudo vim /usr/share/apache-tomcat/webapps/manager/META-INF/context.xml
sudo vim /usr/share/apache-tomcat/webapps/host-manager/META-INF/context.xml
Modify allow line to add IP from which you want to access UI interface.
allow="127.d+.d+.d+|::1|0:0:0:0:0:0:0:1|192.168.1.20" />
Alternatively comment out the IP address restriction to allow connections from anywhere:
<!--<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127.d+.d+.d+|::1|0:0:0:0:0:0:0:1" />-->
Secure Access to admin/manager dashboard
We need to secure access to admin areas of tomcat UI, edit the file:
sudo vim /usr/share/apache-tomcat/conf/tomcat-users.xml
Add the following content before </tomcat-users>
<!-- manager section user role -->
<role rolename="manager-gui" />
<user username="manager" password="StronPassw0rd123" roles="manager-gui" />
<!-- admin section user role -->
<role rolename="admin-gui" />
<user username="admin" password="StronPassw0rd123" roles="manager-gui,admin-gui" />
Configure Systemd service
Create Systemd unit file for Tomcat 10:
sudo vim /etc/systemd/system/tomcat.service
Then paste below content into the file:
[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
Reload systemd daemon:
sudo systemctl daemon-reload
Run the commands below to start the tomcat service:
sudo systemctl restart tomcat
Enable tomcat to start at system boot:
sudo systemctl enable tomcat
If the start was successful, you should see port 8080 on your system being used by a Java process.
$ sudo ss -tunelp | grep 8080
tcp LISTEN 0 100 *:8080 *:* users:(("java",pid=15131,fd=49)) ino:9110112 sk:18 v6only:0 <->
Try to access port 8080 on your web browser using the server IP address or its hostname:
The Manager App console is accessible via the link or http://[server_domain_or_IP]:8080/manager/html
The Web Application Manager allows you to manage your Java applications – Deploy, Start, Stop, Reload, and remove from web console.
You can create Virtual Hosts and configure your applications hosting on Tomcat as you desire.
If you have an active firewall service, allow access to port 8080:
sudo ufw allow 8080
To this end you should have a working installation of Tomcat 10 on Ubuntu 22.04 / 20.04 / 18.04. Your on the roll to deploy your own Java web applications on Tomcat server running on Ubuntu.
Learning Video course & Book:
We have more informative articles in our website related to Tomcat server:
- Install Apache Tomcat on CentOS | Rocky Linux
- Install Apache Tomcat On Ubuntu / CentOS 7 With Ansible
Leave a Reply
You must be logged in to post a comment.