• Home
  • Ubuntu 20.04
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 20.04
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

How to Install Tomcat 9 on Ubuntu 20.04

Written by Rahul, Updated on May 30, 2020

The Apache Tomcat 9 is the latest version available for the installation. Tomcat is an open-source web server for the Java-based applications developed by the Apache Foundation. We use Tomcat for deploying Java Servlet and JSP applications. To know more about the Apache Tomcat visit apache official site http://tomcat.apache.org/.

Prerequisites

A running Ubuntu 20.04 system with shell access of root or sudo privileged account access.

Installing Java

You must have Java installed on your system to run tomcat server. Tomcat 9 required to have Java 8 or higher version installed on your system. Use the following command to install OpenJDK on your system or skip if already installed.

sudo apt install openjdk-11-jdk

Check the current active Java version:

java -version

openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)

Create A Tomcat Account

We recommend to create separate user account to run tomcat web server on Ubuntu system. This will be good for the security purpose.

To create account execute following command:

sudo useradd -m -d /opt/tomcat -U -s /bin/false tomcat

The above command will create a user and group with name “tomcat” on your system.

Download Tomcat Archive

The Apache Tomcat development team releases latest version of Tomcat time to time. So it will be good check download latest Tomcat version from the official download server. Use below command to download Tomcat 9.0.35.

wget https://www-us.apache.org/dist/tomcat/tomcat-9/v9.0.35/bin/apache-tomcat-9.0.35.tar.gz

Once the download completed, extracted downloaded archive and copy all content to tomcat home directory.

tar xzf apache-tomcat-9.0.35.tar.gz
sudo mv apache-tomcat-9.0.35/* /opt/tomcat/

Also, set the proper ownership of all files.

sudo chown -R tomcat:tomcat /opt/tomcat/

You can also download Tomcat 8 instead of Tomcat 9 and change above commands accordingly. Remaining steps will be same for both.

Enable Host/Manager Remote Access

By default Tomcat manager and host-manager, pages are accessible from localhost system only. To allow access these pages from the remote system, you need to create following configuration files.

First create manager xml file:

sudo nano /opt/tomcat/conf/Catalina/localhost/manager.xml

Add the following content

<Context privileged="true" antiResourceLocking="false"
         docBase="{catalina.home}/webapps/manager">
    <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="^.*$" />
</Context>

Then create host-manager xml file:

vim /opt/tomcat/conf/Catalina/localhost/host-manager.xml

Add the following content

<Context privileged="true" antiResourceLocking="false"
         docBase="${catalina.home}/webapps/host-manager">
    <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="^.*$" />
</Context>

Save both files and close.

Create Tomcat Access Credentials

Now, configure your tomcat with user accounts to secure access of admin/manager pages. To do this, edit conf/tomcat-users.xml file in your editor and paste the following code inside <tomcat-users> </tomcat-users> tags. We recommend changing the password in the below configuration with high secured password.

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

Add the following values. Make sure to change password for admin and manager access.

<!-- user manager can access only manager section -->
<role rolename="manager-gui" />
<user username="manager" password="_SECRET_PASSWORD_" roles="manager-gui" />

<!-- user admin can access manager and admin section both -->
<role rolename="admin-gui" />
<user username="admin" password="_SECRET_PASSWORD_" roles="manager-gui,admin-gui" />

Save file and close.

Create A Tomcat Startup Script

Tomcat provides bash scripts to start, stop service. But, to make it simpl, create a startup script to manage Tomcat as systemd service. Let’s create a tomcat.service file with the following content:

sudo nano /etc/systemd/system/tomcat.service
[Unit]
Description=Tomcat
After=network.target

[Service]
Type=forking

User=tomcat
Group=tomcat

Environment="JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"
Environment="CATALINA_BASE=/opt/tomcat"
Environment="CATALINA_HOME=/opt/tomcat"
Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh

[Install]
WantedBy=multi-user.target

Reload the systemd daemon service to apply changes

sudo systemctl daemon-reload

Then, enable and start Tomcat service on your system

sudo systemctl enable tomcat
sudo systemctl start tomcat

Accessing Tomcat

Tomcat server works on port 8080 default. To access Tomcat on the web browser by connecting your server on port 8080.

If you are connecting from the local machine then use http://localhost or use the IP address for the remote system with port:

http://host.tecadmin.net:8080

install tomcat on Ubuntu 20.04

http://host.tecadmin.net:8080/manager/html

Tomcat manager access ubuntu 20.04

http://host.tecadmin.net:8080/host-manager/html

Tomcat host manager ubuntu 20.04

Conclusion

You have a running Tomcat server on Ubuntu system. You may need to create a Virtual host or configure a SSL certificate in Tomcat.

Share it!
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

Leave a Reply Cancel reply

Popular Posts

  • How To Install Python 3.9 on Debian 10
  • Download Ubuntu 20.04 LTS – DVD ISO Images
  • Linux Run Commands As Another User
  • How to Check PHP Version (Apache/Nginx/CLI)
  • How To Install and Configure GitLab on Ubuntu 20.04
  • How to Install PyCharm on Ubuntu 20.04
  • How to Check Ubuntu Version with Command or Script
  • How to Set all directories to 755 And all files to 644
© 2013-2021 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy