linuxize.com Open in urlscan Pro
2606:4700:20::ac43:4aa7  Public Scan

Submitted URL: http://linuxize.com/post/how-to-install-tomcat-9-on-ubuntu-18-04/
Effective URL: https://linuxize.com/post/how-to-install-tomcat-9-on-ubuntu-18-04/
Submission: On September 07 via api from SG

Form analysis 1 forms found in the DOM

Name: mc-embedded-subscribe-formPOST https://linuxize.us17.list-manage.com/subscribe/post?u=35cd4cd9d021c25c3dd7cabfd&id=9cfa4c89de

<form action="https://linuxize.us17.list-manage.com/subscribe/post?u=35cd4cd9d021c25c3dd7cabfd&amp;id=9cfa4c89de" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="pt-8" novalidate="">
  <div class="flex flex-col sm:flex-row items-center justify-between w-full max-w-sm mx-auto mb-2"><input type="email" name="EMAIL" placeholder="Your email..." aria-label="email"
      class="appearance-none block w-full bg-white text-gray-800 border hover:border-gray-700 rounded py-3 px-4 mb-3 sm:mb-0">
    <input type="text" name="b_35cd4cd9d021c25c3dd7cabfd_9cfa4c89de" tabindex="-1" class="hidden">
    <button type="submit" name="subscribe" class="bg-indigo-700 tracking-wide hover:bg-indigo-800 text-white py-3 px-4 sm:ml-4 w-full sm:w-auto rounded">
      <span class="text-center">Subscribe</span></button>
  </div>
  <p class="w-full max-w-sm mx-auto my-0 text-sm">We’ll never share your email address or spam you.</p>
</form>

Text Content

Linuxize
Ubuntu Centos Debian Commands Series Donate



HOW TO INSTALL TOMCAT 9 ON UBUNTU 18.04

Updated  Nov 11, 2019

•

6 min read

Contents

 * Prerequisites
 * Step 1: Install OpenJDK
 * Step 2: Create Tomcat User
 * Step 3: Install Tomcat
 * Step 4: Create a systemd Unit File
 * Step 5: Adjust the Firewall
 * Step 6: Configure Tomcat Web Management Interface
 * Step 6: Test the Tomcat Installation
 * Conclusion

Share:




Apache Tomcat is an open-source implementation of the Java Servlet, JavaServer
Pages, Java Expression Language, and Java WebSocket technologies. It is one of
the most widely adopted application and web servers in the world today. Tomcat
is simple to use and has a robust ecosystem of add-ons.

This tutorial explains how to install and configure Tomcat 9 on Ubuntu 18.04.
The same instructions apply for Ubuntu 16.04 and any Ubuntu-based distribution,
including Linux Mint and Elementary OS.



PREREQUISITES #

To be able to install packages on your Ubuntu system, you must be logged in as a
user with sudo privileges .


STEP 1: INSTALL OPENJDK #

Tomcat requires Java to be installed. We’ll install OpenJDK , which is the
default Java development and runtime in Ubuntu 18.04.

The installation of Java is pretty simple. Begin by updating the package index:

sudo apt update

Install the OpenJDK package by running:

sudo apt install default-jdk


STEP 2: CREATE TOMCAT USER #

For security purposes, Tomcat should not be run under the root user. We will
create a new system user and group with home directory /opt/tomcat that will run
the Tomcat service:


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


STEP 3: INSTALL TOMCAT #

We will download the latest binary release of Tomcat 9 from the Tomcat 9
downloads page .

At the time of writing, the latest version is 9.0.27. Before continuing with the
next step, you should check the download page for a new version. If there is a
new version, copy the link to the Core tar.gz file, which is under the Binary
Distributions section.

Start by download the Tomcat archive in the /tmp directory using the following
wget command:

wget http://www-eu.apache.org/dist/tomcat/tomcat-9/v9.0.27/bin/apache-tomcat-9.0.27.tar.gz -P /tmp

Once the download is complete, extract the Tomcat archive and move it to the
/opt/tomcat directory:

sudo tar xf /tmp/apache-tomcat-9*.tar.gz -C /opt/tomcat

To have more control over Tomcat versions and updates, create a symbolic link
called latest that points to the Tomcat installation directory:


sudo ln -s /opt/tomcat/apache-tomcat-9.0.27 /opt/tomcat/latest

Later if you want to upgrade your Tomcat instance, simply unpack the newer
version and change the symlink to point to the latest version.

As we mentioned in the previous section Tomcat will run under the tomcat user.
This user needs to have access to the tomcat installation directory.

The following command changes the directory ownership to user and group tomcat:

sudo chown -RH tomcat: /opt/tomcat/latest

The scripts inside bin directory must have executable flag :


sudo sh -c 'chmod +x /opt/tomcat/latest/bin/*.sh'


STEP 4: CREATE A SYSTEMD UNIT FILE #

To run Tomcat as a service you need to create a new unit file.

Open your text editor and create a file named tomcat.service in the
/etc/systemd/system/:

sudo nano /etc/systemd/system/tomcat.service

Paste the following configuration:

/etc/systemd/system/tomcat.service

[Unit]
Description=Tomcat 9 servlet container
After=network.target

[Service]
Type=forking

User=tomcat
Group=tomcat

Environment="JAVA_HOME=/usr/lib/jvm/default-java"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom -Djava.awt.headless=true"

Environment="CATALINA_BASE=/opt/tomcat/latest"
Environment="CATALINA_HOME=/opt/tomcat/latest"
Environment="CATALINA_PID=/opt/tomcat/latest/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"

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

[Install]
WantedBy=multi-user.target


Modify the value of JAVA_HOME if the path to your Java installation is
different.

Save and close the file and notify systemd that we created a new unit file:

sudo systemctl daemon-reload

Start the Tomcat service by executing:


sudo systemctl start tomcat

Check the service status with the following command:


sudo systemctl status tomcat

* tomcat.service - Tomcat 9 servlet container
   Loaded: loaded (/etc/systemd/system/tomcat.service; disabled; vendor preset: enabled)
   Active: active (running) since Wed 2018-09-05 15:45:28 PDT; 20s ago
  Process: 1582 ExecStart=/opt/tomcat/latest/bin/startup.sh (code=exited, status=0/SUCCESS)
 Main PID: 1604 (java)
    Tasks: 47 (limit: 2319)
   CGroup: /system.slice/tomcat.service


If there are no errors enable the Tomcat service to be automatically started at
boot time:

sudo systemctl enable tomcat


STEP 5: ADJUST THE FIREWALL #

If your server is protected by a firewall and you want to access Tomcat from the
outside of your local network, you need to open port 8080.

To allow traffic on port 8080 type the following command:

sudo ufw allow 8080/tcp

Usually when running a Tomcat application in a production environment you will
have a load balancer or reverse proxy . It’s a best practice to restrict access
to port 8080 only to your internal network.


STEP 6: CONFIGURE TOMCAT WEB MANAGEMENT INTERFACE #

Now that Tomcat is installed and running, the next step is to create a user with
access the web management interface.


Tomcat users and roles are defined in the tomcat-users.xml file. This file is a
template with comments and examples describing how to configure user or role.

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

To add a new user with access to the Tomcat web interface (manager-gui and
admin-gui) we need to define the user in the tomcat-users.xml file, as shown
below. Make sure you change the username and password to something more secure:

/opt/tomcat/latest/conf/tomcat-users.xml

<tomcat-users>
<!--
    Comments
-->
   <role rolename="admin-gui"/>
   <role rolename="manager-gui"/>
   <user username="admin" password="admin_password" roles="admin-gui,manager-gui"/>
</tomcat-users>

By default Tomcat web management interface is configured to restrict access to
the Manager and Host Manager apps only from the localhost.

If you want to be able to access the web interface from a remote IP, you will
have to remove these restrictions. This may have various security implications,
and it is not recommended for production systems.

To enable access to the web interface from anywhere open the following two files
and comment or remove the lines highlighted in yellow.


For the Manager app, open the following file:

sudo nano /opt/tomcat/latest/webapps/manager/META-INF/context.xml

For the Host Manager app, open the following file:

sudo nano /opt/tomcat/latest/webapps/host-manager/META-INF/context.xml

context.xml

<Context antiResourceLocking="false" privileged="true" >
<!--
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
-->
</Context>

Another option is to allow access to the to the Manager and Host Manager apps
only from a specific IP. Instead of commenting the blocks you can simply add
your IP address to the list.

For example if your public IP is 45.45.45.45 you would make the following
change:

context.xml

<Context antiResourceLocking="false" privileged="true" >
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|45.45.45.45" />
</Context>

The list of allowed IP addresses is a list separated with vertical bar |. You
can add single IP addresses or use a regular expressions.

Remember to restart the Tomcat service each time you edit Tomcat configuration
files for changes to take effect:

sudo systemctl restart tomcat


STEP 6: TEST THE TOMCAT INSTALLATION #

Open your browser and type: http://<your_domain_or_IP_address>:8080

Assuming the installation is successful, a screen similar to the following
should appear:



Tomcat web application manager dashboard is available at
http://<your_domain_or_IP_address>:8080/manager/html. From here, you can deploy,
undeploy, start, stop, and reload your applications.

You can sign in with the user you have created in Step 6.



Tomcat virtual host manager dashboard is available at
http://<your_domain_or_IP_address>:8080/host-manager/html. From here, you can
create, delete and manage Tomcat virtual hosts.




CONCLUSION #

You have successfully installed Tomcat 9 on your Ubuntu 18.04 system. You can
now visit the official Apache Tomcat 9 Documentation and learn more about the
Apache Tomcat features.

If you hit a problem or have feedback, leave a comment below.

java tomcat ubuntu

Not using Ubuntu 18.04?
Choose different OS:
centos 7
centos 8
debian 10
debian 9
ubuntu 20.04

Related Tutorials

 * How to Install Tomcat 8.5 on Ubuntu 18.04
 * How to Install Tomcat 9 on Ubuntu 20.04
 * How to Install Minecraft Server on Ubuntu 18.04
 * How to Install Tomcat 9 on Debian 9
 * How to Install Tomcat 9 on CentOS 7
 * How to Install Gradle on Ubuntu 18.04
 * How to Install Apache Maven on Ubuntu 18.04




If you like our content, please consider buying us a coffee.
Thank you for your support!

Buy me a coffee

Sign up to our newsletter and get our latest tutorials and news straight to your
mailbox.

Subscribe

We’ll never share your email address or spam you.


RELATED ARTICLES

May 5, 2018


HOW TO INSTALL TOMCAT 8.5 ON UBUNTU 18.04



May 25, 2020


HOW TO INSTALL TOMCAT 9 ON UBUNTU 20.04



Dec 27, 2018


HOW TO INSTALL MINECRAFT SERVER ON UBUNTU 18.04


Write a comment

Please enable JavaScript to view the comments powered by Disqus.
ESC

© 2021 Linuxize.com Privacy Policy Terms Contact Advertise on Linuxize

ENFRDEESITHRSVSRSLNL


THIS WEBSITE USES COOKIES

This website use cookies to personalize content, provide custom experiences,
target ads, to provide social media features and to analyse our traffic. We also
share information about your use of our site with our social media, advertising
and analytics partners who may combine it with other information that you've
provided to them or that they've collected from your use of their services.
Below you have the option of selecting which types of cookies you'll allow to
store your personal information. To view the vendor list or change consent
settings at any time please visit our privacy policy using the link below.

Continue with Recommended Cookies

Vendor List | Cookie Details | Privacy Policy