The objective of this guide is to help install and configure Apache Tomcat 10.x on Ubuntu 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 20.04/18.04. Without much theory let’s proceed to install and configure Java Development Kit / OpenJDK on Ubuntu

Step 1: Install Java Ubuntu 20.04/18.04

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

Step 2: Install Apache Tomcat 10 on Ubuntu 20.04/18.04

Now that we have Java Open JDK installed, we should be ready to start the installation of Apache Tomcat on Ubuntu 20.04/18.04. The installation process is as below:

Download Apache Tomcat archive

Let’s download Apache tomcat 10 using wget:

sudo apt install wget
wget https://downloads.apache.org/tomcat/tomcat-10/v10.0.6/bin/apache-tomcat-10.0.6.tar.gz

Extract tar archive and install Tomcat

After the download extract the archive file:

tar xvf apache-tomcat-10.0.6.tar.gz

Move extracted files to /usr

sudo mv apache-tomcat-10.0.6 /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 on Ubuntu 20.04/18.04

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:

install apache tomcat ubuntu 01

The Manager App console is accessible via the link or http://[server_domain_or_IP]:8080/manager/html

install apache tomcat ubuntu 02

The Web Application Manager allows you to manage your Java applications – Deploy, Start, Stop, Reload, and remove from web console.

install apache tomcat ubuntu 03

Start

tomcat install debian 04

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 20.04 / 18.04. Your on the roll to deploy your own Java web applications on Tomcat server running on Ubuntu.

Your support is our everlasting motivation,
that cup of coffee is what keeps us going!


As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.

LEAVE A REPLY

Please enter your comment!
Please enter your name here