Compute Engine Google Cloud

Install Apache Tomcat on Ubuntu 20.04 – Google Cloud

Install Apache Tomcat on Ubuntu 20.04 in Google Cloud. Tomcat is a widely used web application server that is used to serve Java applications.

In this tutorial guide you are gong to learn how to install and configure Apache Tomcat on Ubuntu 20.04.

This setup is tested on Google Cloud Compute Engine Instance running Ubuntu 20.04. So, this setup will work fine on any cloud servers or any VPS or Dedicated servers.

Choose Best Hosting for your Business

Kinsta – Google Cloud★★★★★$30


  1. Your Compute Engine Instance running.
  2. For setting up Compute Engine, see the Setting up Compute Engine Instance with Ubuntu 20.04.

Step 1: Install Java 11

Once your Google Compute Engine is up and running, connect to your instance using SSH and start by updating the packages.

sudo apt update
sudo apt upgrade

Java is required for Tomcat to serve Java applications. You can install Java 11 using the following command.

sudo apt install openjdk-11-jdk  

Once Java is installed you can proceed to next step.

Step 2: Create and Setup Tomcat User

For security purposes we shall create a non root user to run the Tomcat service.

 sudo groupadd tomcat 

Now you can create a new tomcat user and assign it to the home directory /opt/tomcat where we are going to install Tomcat.

 sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat

Step 3: Install Apache Tomcat

Now download the latest binary release of Tomcat for the official Tomcat downloads page. Under the Binary Distributions, under Core, copy the link of the file with extension tar.gz

Create the directory for Tomcat installation.

sudo mkdir /opt/tomcat

Download Tomcat with the link you have copied.

cd /tmp
curl -O
sudo tar xzvf apache-tomcat-9.0.35.tar.gz -C /opt/tomcat --strip-components=1

Step 4: Setup Permissions

Move to the directory of the Tomcat installation.

cd /opt/tomcat

Setup correct permissions for tomcat user.

sudo chgrp -R tomcat /opt/tomcat
sudo chmod -R g+r conf
sudo chmod g+x conf
sudo chown -R tomcat webapps/ work/ temp/ logs/

Step 5: Create Service

To run Tomcat as a service you need to setup this with a systemd service file.

Locate the path of Java installation. Execute the below command to find the installation path.

sudo update-java-alternatives -l
java-1.11.0-openjdk-amd64       1081       /usr/lib/jvm/java-1.11.0-openjdk-amd64

Now, create a new file for Tomcat inside /etc/systemd/system directory.

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

Make sure to modify the JAVA_HOME with the path of your Java installation.

Description=Apache Tomcat Web Application Container


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




Hit Ctrl + X followed Y and Enter to save and exit the file.

Reload the systemd daemon.

sudo systemctl daemon-reload

Now you can start Tomcat server.

sudo systemctl start tomcat

Finally enable Tomcat to startup on system boot.

sudo systemctl enable tomcat

Step 6: Configure Tomcat

To use the manager web app you need to login to the server. To setup your username and password edit the tomcat-users.xml file.

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

Add the <user tag within the <tomcat-users which should look like the one below.

<tomcat-users . . .>
    <user username="admin" password="password" roles="manager-gui,admin-gui"/>

Hit Ctrl + X followed Y and Enter to save and exit the file.

By default Tomcat restricts access to Manager and Host manager. So, to allow connections you need to remove the IP restrictions by commenting out the listed lines from the corresponding context.xml files.

For the Manager app the file that needs be updated is:

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

For the Host Manager app the file that needs be updated is:

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

Comment out the valve section to remove the IP restriction as shown below.

<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" />-->

Hit Ctrl + X followed Y and Enter to save and exit the file.

Step 7: Configure Firewall

By default Tomcat runs on port 8080, So you need to open port 8080 to allow connections.

In your Google Cloud Console go to VPC Network >> Firewall rules and click Create Firewall rules.

In Name enter tomcat

In Targets select All instances in the network

In Source filter select IP ranges

In Source IP ranges enter

In Protocols and ports check TCP and enter 8080.

Click Create.

Step 8: Access Web Interface

Now you can access your Tomcat web manager with your external IP address followed by port 8080.


You will see the Tomcat welcome page.

Tomcat Welcome Page

Tomcat Web Application Manager page.

Tomcat Web Application Manager

Tomcat Virtual Host Manager.

Tomcat Virtual Host Manager


Now you have learned how to install Apache Tomcat and configure Manager app and Host manager also on Ubuntu 20.04 LTS.

Thanks for your time. If you face any problem or any feedback, please leave a comment below.

Cloudbooklet builds a large collection of Linux based guides and tutorials on Cloud platforms like Google Cloud, AWS, Azure, DigitalOcean and more

1 Comment

  1. Just want to Thank you. actually i was struggling a lot. This article is so beautiful, it resolved all my issues. Thank you so much again!

Write A Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

If you find this helpful? Support me!
Buy me a coffee Donation Please buy me a coffee