Install Apache Tomcat and Java on Your EC2 instance

Samuel .O
4 min readMar 4, 2021

--

Tomcat is a Java Servlet container and a web sever from the apache software foundation. It can be used as a standalone or behind traditional web servers such as apache httpd. A web server uses the request/response message exchange pattern to serve web pages. Want to know more about apache tomcat, click here .

Overview:

Here, I will show you how to set up an amazon ec2 instance on the AWS management console. I will also install java and apache tomcat on this instance to help deploy a java web application on AWS.

Step 1

Launch your ec2 instance in a default vpc or a custom vpc, then connect the instance to the network. Refer to “building a vpc to create an instance and connecting it to the server” Click here

Then update the privilege to root and do a yum update.

Step 2

Install java on the ec2 instance by configuring the java sdk package. Try to organize your work by creating a folder in the instance directory like i did. In order to do this easily, you need to have some basic knowledge of linux(RedHat or CentOs). I found this whole java setup files handy by using the one and only stack overflow to get my version of java to. download. The highlighted one you see below was what i actually downloaded on to my instance.

After you have copied that whole rpm file from stack overflow, then paste it on your CLI and run it.

Then after the process, use the following command to unpack the jar files then check to see the version you installed.

sudo rpm -i jdk-8u131-linux-x64.rpm

Step 3

Install apache tomcat on the ec2 machine. First of of, visit the site here to get the compressed tar folder for the apache sever version.

I am currently installing apache tomcat 9. Copy the tar file and paste it on the CLI, then run it. when that is done, go into the apache-tomcat -9.0.43 folder and open up the bin folder to startup the tomcat server using the shell file. “./startup.sh” . Next step is to run the command below and please see the detailed explanation on the reason behind that command.

ps -ef | grep tomcat
  • ps - list processes
  • -e - show all processes, not just those belonging to the user
  • -f - show processes in full format (more detailed than default)
  • grep find lines containing a pattern
  • look for lines containing tomcat in a detailed overview/snapshot of all current processes, and display those lines

Then connect the tomcat server to the local host using the following command

wget http://localhost:8080/

Step 4

Use the vi editor to edit the xml file by making the configuration a comment so it doesnt execute. By default the configuration settings wouldn’t help the ec2 instance to run.

vi webapps/manager/META-INF/context.xml

Here is a displayed diagram of your working ec2 instance.

Now open the public DNS address on your browser to see the tomcat server working. Incase this doesn’t work right away, please do edit your inbound security group of your ec2 instance to open custom TCP to port 8080 for the source 0.0.0.0/0 for ipv4 and ::/0 for ipv6. Then refresh the address and you will get the following displayed page below.

Next, I will show you how to deploy your web application on your ec2 instance using apache tomcat.

Services

ec2

visualisation

draw.io

Thanks for reading….

--

--

Samuel .O
Samuel .O

No responses yet