AWS Tutorial: How to install Tomcat 9 in AWS EC2 Instance

AWS Tutorial: How to install Tomcat 9 in AWS EC2 Instance

In this tutorial I will show you how you install Tomcat Server in your AWS Linux.

Prerequisite:

  1. AWS Account and login to AWS Console, here.
  2. Create an AWS EC2 with Amazon Linux 2 AMI instance and Instance type between *micro-*small.
  3. Install Java JDK on Amazon Linux, here.

1) Install Tomcat:

Go to tomcat.apache.org/download and find the latest stable version of tomcat, as this tutorial wrote, tomcat 9.0.41 is the latest stable we can use. Get the URL address of "tar.gz" file below;

tomcat9-download

Go in your in your EC2 instance and remember log as "sudo" 1st before you execute below command:

wget https://downloads.apache.org/tomcat/tomcat-9/v9.0.41/bin/apache-tomcat-9.0.41.tar.gz

2) Extract TAR file
Go /usr/local or /usr/shared and then extract the TAR file you downloaded in previous step.

tar -xvf /root/apache-tomcat-9.0.41.tar.gz

3) Rename the Tomcat

Rename tomcat to simplest name so easy for us to maintain in later stage.

mv apache-tomcat-9.0.41 tomcat9

After that your "tomcat9" will look like below;

Tomcat-Folder-Structure

4) Add User for Tomcat

useradd -r tomcat

5) Give User Permission
Give permission user to tomcat9 folder:

chown -R tomcat:tomcat /usr/local/tomcat9

6) Create Tomcat Service

Copy below script for your Tomcat Service file

sudo tee /etc/systemd/system/tomcat.service<<EOF
[Unit]
Description=Tomcat Server
After=syslog.target network.target

[Service]
Type=forking
User=tomcat
Group=tomcat

Environment=CATALINA_HOME=/usr/local/tomcat9
Environment=CATALINA_BASE=/usr/local/tomcat9
Environment=CATALINA_PID=/usr/local/tomcat9/temp/tomcat.pid

ExecStart=/usr/local/tomcat9/bin/catalina.sh start
ExecStop=/usr/local/tomcat9/bin/catalina.sh stop

RestartSec=12
Restart=always

[Install]
WantedBy=multi-user.target
EOF

7) Enable and start tomcat service:

#Reload tomcat service
sudo systemctl daemon-reload

#Restart/Start tomcat service
sudo systemctl start tomcat

#Check tomcat service status
systemctl status tomcat.service

8) Check Tomcat Service and Host-Manager(GUI)

tomcat-service-status

Finally we check on our browser the Tomcat Server GUI via http://[AWS EC2 Public IP]:8080

succeed-tomcat

Recap

  1. We have created an AWS Instance with Amazon Linux OS
  2. We installed Java JDK 11 for tomcat dependency.
  3. Installed Tomcat Server in our EC2 instance.
  4. We able successfully accessed Tomcat Server Host-Manager(GUI) via browser.

Share Tweet Send
0 Comments
Loading...
You've successfully subscribed to DevOps4Me
Great! Next, complete checkout for full access to DevOps4Me
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.