Geekflare is supported by our audience. We may earn affiliate commissions from buying links on this site.
Share on:

How to Install Tomcat 9 and Where to Host it?

tomcat
Invicti Web Application Security Scanner – the only solution that delivers automatic verification of vulnerabilities with Proof-Based Scanning™.

Learn how to install Tomcat and some of the cloud hosting option to deploy your Tomcat applications.

There are two parts to this blogpost – the first part talks about how to install Apache Tomcat on Ubuntu by yourself, and the second part talks about the best hosting platforms available to host Tomcat applications.

What is Apache Tomcat?

Apache Tomcat is an open-source web/application server from the Apache foundation. It was formerly called Jakarta. It is an HTTP server and a servlet container. By default, it runs on port 8080.

Tomcat implements the java servlets and the Java server pages specifications. It provides a Java web server environment for Java code to run in. Apache Tomcat includes configuration and management tools. It can also be configured directly by editing the XML configuration file.

Here is a step by step guide to install Tomcat 9 on Ubuntu 18.04.

Prerequisite

To install Tomcat, you need to have java installed on your system.

Update the repository and install Java 8.

sudo apt-get update
sudo apt-get install openjdk-8-jdk -y

Choose Java 8 you just installed as the current Java version.

sudo update-alternatives --config java

Check the Java version.

geekflare@geekflare:~$ java -version
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b03-0ubuntu1.18.10.1-b03)
OpenJDK 64-Bit Server VM (build 25.212-b03, mixed mode)

Install Tomcat 9

Download the latest package of Tomcat 9 version, currently its tomcat-9.0.27. You can always refer to the official download link for the latest version.

https://tomcat.apache.org/download-90.cgi

The below example is for 9.0.27.

  • Download the Tomcat package
geekflare@geekflare:~$ wget http://www-eu.apache.org/dist/tomcat/tomcat-9/v9.0.27/bin/apache-tomcat-9.0.27.tar.gz
--2019-11-18 14:29:04-- http://www-eu.apache.org/dist/tomcat/tomcat-9/v9.0.27/bin/apache-tomcat-9.0.27.tar.gz
Resolving www-eu.apache.org (www-eu.apache.org)... 95.216.24.32, 2a01:4f9:2a:185f::2
Connecting to www-eu.apache.org (www-eu.apache.org)|95.216.24.32|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10982406 (10M) [application/x-gzip]
Saving to: ‘apache-tomcat-9.0.27.tar.gz’

apache-tomcat-9.0.27.tar.gz 100%[=================================================================>] 10.47M 3.87MB/s in 2.7s

2019-11-18 14:29:38 (3.87 MB/s) - ‘apache-tomcat-9.0.27.tar.gz’ saved [10982406/10982406]
  • Extract the Tomcat 9 package
geekflare@geekflare:~$ tar -xzf apache-tomcat-9.0.27.tar.gz
  • For security reasons, we will create a separate system user for Tomcat.
geekflare@geekflare:~$ sudo useradd -r -m -U -d /home/geekflare/apache-tomcat-9.0.27 -s /bin/false tomcat
[sudo] password for geekflare:
  • The tomcat user should have complete access to the Tomcat installation directory. This command changes the installation directory ownership to the tomcat user.
geekflare@geekflare:~$ sudo chown -RH tomcat: apache-tomcat-9.0.27
  • All the scripts inside the bin directory of tomcat must be executable, so add the executable permission.
geekflare@geekflare:~$ sudo sh -c 'chmod +x apache-tomcat-9.0.27/bin/*.sh'
  • Create a file tomcat.service inside /etc/systemd/system/ to run tomcat as a service.

Wondering why? well, this is to ensure Tomcat starts automatically when server reboot.

geekflare@geekflare:~$ sudo gedit /etc/systemd/system/tomcat.service
  • Copy-paste the content below in the file. Change the JAVA_HOME path according to your java installation path.
[Unit]

Description=Tomcat 9 servlet container

After=network.target

[Service]

Type=forking

User=tomcat

Group=tomcat

Environment="JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64"

Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom -Djava.awt.headless=true"

Environment="CATALINA_BASE=/home/geekflare/apache-tomcat-9.0.27"

Environment="CATALINA_HOME=/home/geekflare/apache-tomcat-9.0.27"

Environment="CATALINA_PID=/home/geekflare/apache-tomcat-9.0.27"

Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"

ExecStart=/home/geekflare/apache-tomcat-9.0.27/bin/startup.sh

ExecStop=/home/geekflare/apache-tomcat-9.0.27/bin/shutdown.sh

[Install]

WantedBy=multi-user.target
  • Run the below command to tell the system about the new service file you just created.
geekflare@geekflare:~$ sudo systemctl daemon-reload
  • Start the tomcat service.
geekflare@geekflare:~$ sudo systemctl start tomcat
  • Check if the tomcat service is in the running mode or not.
geekflare@geekflare:~$ systemctl status tomcat.service
● tomcat.service - Tomcat 9 servlet container
Loaded: loaded (/etc/systemd/system/tomcat.service; disabled; vendor preset: enabled)
Active: active (running) since Mon 2019-11-18 14:41:12 EST; 4s ago
Process: 22939 ExecStart=/home/geekflare/apache-tomcat-9.0.27/bin/startup.sh (code=exited, status=0/SUCCESS)
Main PID: 22947 (java)
Tasks: 14 (limit: 4680)
Memory: 63.0M
CGroup: /system.slice/tomcat.service
└─22947 /usr/lib/jvm/java-1.8.0-openjdk-amd64/bin/java -Djava.util.logging.config.file=/home/geekflare/apache-tomcat-9.0.27/conf/logg

Nov 18 14:41:12 geekflare systemd[1]: Starting Tomcat 9 servlet container...
Nov 18 14:41:12 geekflare systemd[1]: Started Tomcat 9 servlet container.
  • You can ask the system to automatically start tomcat at boot time by running the command below.
geekflare@geekflare:~$ sudo systemctl enable tomcat
Created symlink /etc/systemd/system/multi-user.target.wants/tomcat.service → /etc/systemd/system/tomcat.service.
  • Make sure your firewall does not stop Tomcat from running. Open port 8080 on which tomcat runs.
geekflare@geekflare:~$ sudo ufw allow 8080/tcp
Rules updated
Rules updated (v6)
  • Edit the tomcat-users.xml file where all the users and roles are defined for the tomcat web management interface.
geekflare@geekflare:~$ sudo gedit apache-tomcat-9.0.27/conf/tomcat-users.xml
  • I am giving a tomcat user manager-gui role also, which allows it to access the web management interface with a different credential.
<?xml version="1.0" encoding="UTF-8"?>

<!--

Licensed to the Apache Software Foundation (ASF) under one or more

contributor license agreements. See the NOTICE file distributed with

this work for additional information regarding copyright ownership.

The ASF licenses this file to You under the Apache License, Version 2.0

(the "License"); you may not use this file except in compliance with

the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.

-->

<tomcat-users xmlns="http://tomcat.apache.org/xml"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"

version="1.0">

<!--

NOTE: By default, no user is included in the "manager-gui" role required

to operate the "/manager/html" web application. If you wish to use this app,

You must define such a user - the username and password are arbitrary. It is

strongly recommended that you do NOT use one of the users in the commented out

the section below since they are intended for use with the examples web

application.

-->

<!--

NOTE: The sample user and role entries below are intended for use with the

examples web application. They are wrapped in a comment and thus are ignored

when reading this file. If you wish to configure these users for use with the

examples web application, do not forget to remove the <!.. ..> that surrounds

them. You will also need to set the passwords to something appropriate.

-->

<!--

-->

<role rolename="tomcat"/>

<role rolename="manager-gui"/>

<user username="tomcat" password="tomcat" roles="tomcat"/>

<user username="tomcat" password="admin" roles="manager-gui"/>
</tomcat-users>
tomcat web ui
  • Now go to http://localhost:8080/manager/html, where the web dashboard of tomcat is present. You will be asked to log in, use username tomcat and password admin to login. Using this interface, you can start, stop, reload, deploy an application with a click of a button.
tomcat web application manager

Congratulations! You have successfully installed Tomcat 9 on Ubuntu 18.04.

Now the second part about the hosting platforms and their features.

A2 Hosting

A2 hosting platform claims its Tomcat hosting to be the fastest, easiest, and most reliable. On A2, you can run 20X faster using A2’s Turbo boost VPS.

They offer 24×7 support with any hosting issue you come across on their platform with a 99.9% uptime guarantee. That makes A2 a very reliable hosting platform.

a2-hosting-tomcat

It gives you enough options to customize the resources you need on the platform. A2 is developer-friendly and gives you the root access to all server’s files, which you are free to edit as per your need. There is a risk-free Anytime Money Back Guarantee in case you do not like the hosting platform and want to stop the usage.

Kamatera

Kamatera is a popular cloud hosting platform. It helps you set up, configure, and launch tomcat in seconds. You can choose the tomcat version you want to host and also the zone (region) where you want to host from a straightforward user interface.

tomcat3

Pricing is very attractive.

You can get it started from as low as $4 per month.

Depending on the configuration you choose, there is a wide range of pricing options offered by Kamatera. You can choose from a monthly pricing option or even hourly pricing option. The best part is the first 30 days are entirely free.

tomcat4

Virtuozzo

Virtuozzo offers a multi-cloud configuration where you can host applications on different clouds for extra high availability. Here, you can get a combination of PaaS (Platform as a Service) and CaaS (Container as a Service) models.

With its simple user interface, you can easily select the tomcat application and its version. Then, launching only takes a few seconds.

Tomcat-installation-on-Virtuozzo-1

Automatic Tomcat Clustering in Virtuozzo offers a high availability feature. So, if any tomcat instance fails, another instance gets started automatically. Your tomcat cluster can automatically scale vertically and horizontally in Virtuozzo. However, you can manually scale your cluster horizontally as well.

Some other features that Virtuozzo offers are:

  • Support for microservices and legacy applications
  • Integrated CI and CD tools for automation
  • Quick setup of clustered applications
  • Built-in monitoring system with alert notification
  • Integrated IDE Plugins: IntelliJ IDEA, Eclipse, NetBeans
  • Automated traffic distribution for deployment without any downtime
  • Sharing environment and account collaboration with different access levels
  • Marketplace with a rich set of preconfigured applications for one-click installation

JavaPipe

Another hosting platform is Java Hosting Service for Tomcat. It contains built-in plugins for hibernate, Spring MVC, Servlets and JSPs, Grails, Play, and many more.

With JavaPipe, you can start with as low as $ 5.40 per month, which gives you dedicated Tomcat instance versions 7, 8, or 9 with JDK 7, 8, 10, or 11 support. It gives you 128 MB to 2 GB dedicated RAM and unlimited access to MariaDB. You also get 200 GB of monthly traffic and 5 GB of SSD storage. There are other pricing options also with Java Hosting platform offering more monthly traffic and SSD storage.

Also, you get 40% off if you pay for three years. So, if can think of a long term hosting plan, this could be beneficial.

tomcat7

Conclusion

That was all about Tomcat installation and hosting platforms. If you are interested in hosting Tomcat yourself but on the cloud, then check out these platforms.

Thanks to our Sponsors
More great readings on Hosting
Power Your Business
Some of the tools and services to help your business grow.
  • Invicti uses the Proof-Based Scanning™ to automatically verify the identified vulnerabilities and generate actionable results within just hours.
    Try Invicti
  • Web scraping, residential proxy, proxy manager, web unlocker, search engine crawler, and all you need to collect web data.
    Try Brightdata
  • Semrush is an all-in-one digital marketing solution with more than 50 tools in SEO, social media, and content marketing.
    Try Semrush
  • Intruder is an online vulnerability scanner that finds cyber security weaknesses in your infrastructure, to avoid costly data breaches.
    Try Intruder