Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
No Result
View All Result
Home Google Cloud

Install Apache Tomcat on Ubuntu 20.04 – Google Cloud

by Cloudbooklet
3 years ago
in Google Cloud, Compute Engine
Install Apache Tomcat On Ubuntu 20.04 - Google Cloud
ShareTweetSendShare
Readers like you help support Cloudbooklet. When you make a purchase using links on our site, we may earn an affiliate commission.

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 […]

ADVERTISEMENT

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.

ADVERTISEMENT

Prerequisites

  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.

You might also like

How To Setup Ssh Keys On Ubuntu

How to Setup SSH Keys on Ubuntu 20.04

4 months ago
Draggan Ai Editing Tool Install And Use Draggan Photo Editor

DragGAN AI Editing Tool Install and Use DragGAN Photo Editor

4 months ago
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.

ADVERTISEMENT

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.

ADVERTISEMENT
 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.

ADVERTISEMENT
sudo mkdir /opt/tomcat

Download Tomcat with the link you have copied.

cd /tmp
curl -O http://mirrors.estointernet.in/apache/tomcat/tomcat-9/v9.0.35/bin/apache-tomcat-9.0.35.tar.gz
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.

ADVERTISEMENT
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
Output
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.

[Unit]
Description=Apache Tomcat Web Application Container
After=network.target

[Service]
Type=forking

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

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

User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target

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

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

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 0.0.0.0/0

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.

http://IP_ADDRESS: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

Conclusion

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.

Tags: Google Cloud PlatformTomcatUbuntu 20.04
ShareTweetSendShare
Cloudbooklet

Cloudbooklet

Comments 2

  1. Avatar Of Hemanth Hemanth says:
    3 years ago

    I was struggling a lot to install Tomcat 9 server, found it really useful.

    Reply
  2. Avatar Of Just Me Just Me says:
    3 years ago

    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!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related Posts

Set Up Deep Learning With Nvidia, Cuda, Cudnn On Ubuntu

How to Set Up Deep Learning with Nvidia, CUDA, cuDNN on Ubuntu 22.04

7 months ago
How To Install Or Upgrade Php 8.2 On Ubuntu 22.04

How to Install or Upgrade PHP 8.2 on Ubuntu 22.04

9 months ago
How To Change Timezone On Ubuntu 22.04

How to Change Timezone on Ubuntu 22.04

1 year ago
How To Install Ansible On Ubuntu 22.04

How to Install Ansible on Ubuntu 22.04

1 year ago

Follow Us

Trending Articles

Cloud Vps Server

Top 10 Advantages of a Cloud VPS Server

September 19, 2023

How to Become an AI Trainer: Skills, Salary, and Career Opportunities

5 FREE AI Horoscope Online – Personalized Way to See Your Future

Amazon Prime Big Deal Days 2023: Best Deals

Create High Quality AI Cover Song with Covers AI

How to Delete Netflix Account Permanently

Popular Articles

Fake Nude Generator

10 Best Free Naked AI Generator: Make Realistic Naked Photos

September 20, 2023

7 Best Onlyfans Video Downloaders – Chrome Extensions, Apps, Websites

7 Best AI Face Generator: Create Realistic Faces from Text Online Free

10 Best AI Summarizer Tools in 2023: A Review and Comparison

7 Best AI Album Cover Generators to Create Stunning Artwork

Notepad++ v8.5.7: What’s New and How to Download It

Subscribe Now

loader

Subscribe to our mailing list to receives daily updates!

Email Address*

Name

Cloudbooklet Logo

Welcome to our technology blog, where we explore the latest advancements in the field of artificial intelligence (AI) and how they are revolutionizing cloud computing. In this blog, we dive into the powerful capabilities of cloud platforms like Google Cloud Platform (GCP), Amazon Web Services (AWS), and Microsoft Azure, and how they are accelerating the adoption and deployment of AI solutions across various industries. Join us on this exciting journey as we explore the endless possibilities of AI and cloud computing.

  • About
  • Contact
  • Disclaimer
  • Privacy Policy

Cloudbooklet © 2023 All rights reserved.

No Result
View All Result
  • News
  • Artificial Intelligence
  • Applications
  • Linux

Cloudbooklet © 2023 All rights reserved.