Tomcat installation on EC2 instance

Maaz MohdMaaz Mohd
2 min read

EC2 instance with Java 11

The first thing we need to do is to set up java on the ec2-instance using the command below.

sudo yum update
sudo amazon-linux-extras install java-openjdk11 -y

Install Apache Tomcat

Download tomcat packages from https://tomcat.apache.org/download-90.cgi onto /opt on EC2 instance.

Note: Make sure you change <version> with the tomcat version which you download.

# Create tomcat directory
cd /opt
wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.76/bin/apache-tomcat-9.0.76.tar.gz

To unzip the apache tomcat package which is in tar.gz form we use the command.

tar -xvzf /opt/apache-tomcat-<version>.tar.gz

Give executing permissions to startup.sh and shutdown.sh which are under bin.

chmod +x /opt/apache-tomcat-<version>/bin/startup.sh 
chmod +x /opt/apache-tomcat-<version>/bin/shutdown.sh

Note: you may get the below error while starting tomcat in case if you don't install Java
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environment variable is needed to run this program

Create link files for tomcat startup.sh and shutdown.sh

ln -s /opt/apache-tomcat-<version>/bin/startup.sh /usr/local/bin/tomcatup
ln -s /opt/apache-tomcat-<version>/bin/shutdown.sh /usr/local/bin/tomcatdown
tomcatup

Access tomcat application from browser on port 8080

http://<Public_IP>:8080

Tomcat application doesn't allow login from the browser. changing a default parameter in context.xml does address this issue.

#search for context.xml
find / -name context.xml

Above command gives context.xml files. comment () Value ClassName field on files that are under web app directory. After that restart tomcat services to effect these changes. At the time of writing this lecture below 2 files are updated.

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

# Restart tomcat services
tomcatdown  
tomcatup

Update users information in the tomcat-users.xml file goto tomcat home directory and Add the below users to conf/tomcat-users.xml file

 <role rolename="manager-gui"/>
 <role rolename="manager-script"/>
 <role rolename="manager-jmx"/>
 <role rolename="manager-status"/>
 <user username="admin" password="admin" roles="manager-gui, manager-script, manager-jmx, manager-status"/>
 <user username="deployer" password="deployer" roles="manager-script"/>
 <user username="tomcat" password="s3cret" roles="manager-gui"/>

Restart serivce and try to login to tomcat application from the browser. This time it should be Successful.

1
Subscribe to my newsletter

Read articles from Maaz Mohd directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Maaz Mohd
Maaz Mohd

Hey there! I am Maaz Mohd!! I started writing articles on my DevOps and cloud journey. I will be sharing concepts that I learn, Projects that I built, and the tasks that I Perform related to DevOps. Welcome to my blog!!