Installing and Accessing Tomcat Web-App server in EC2 server

gitgeetansh

Git-Geetansh

Posted on September 18, 2024

Installing and Accessing Tomcat Web-App server in EC2 server

Prerequisites

  1. AWS Account: Ensure you have an active AWS account.
  2. EC2 Instance: Launch an Ubuntu EC2 instance.
  3. Security Group: Configure the security group to allow inbound traffic on port 22 (SSH) and port 8080 (Tomcat).
  4. SSH Client: Have an SSH client like PuTTY or terminal for connecting to your EC2 instance.
  5. Java Development Kit (JDK): Ensure you have JDK installed on your local machine for compiling Java code.

Safety Best Practices

  1. Use IAM Roles: Assign an IAM role to your EC2 instance for secure access to AWS services.
  2. Security Groups: Restrict access to your EC2 instance by configuring security group rules.
  3. Regular Updates: Keep your system and software up to date with the latest security patches.
  4. Backup: Regularly backup your data and configurations.

Steps to Install Tomcat on AWS EC2 Ubuntu Instance

Step 1: Launch an EC2 Instance

  • Log in to your AWS Management Console.
  • Navigate to the EC2 Dashboard and click on “Launch Instance”.
  • Choose the Ubuntu Server.
  • Select an instance type (e.g., t2.micro for free tier).
  • Configure instance details and add storage as needed.
  • Configure the security group to allow SSH (port 22) and HTTP (port 80) traffic.
  • Review and launch the instance. Download the key pair for SSH access.

Inbound rules for security group
Allow custom TCP rule for port 8080

Step 2: Connect to Your EC2 Instance

  • Open your terminal or SSH client.
  • Connect to your instance using the command:

ssh -i /path/to/your-key-pair.pem ubuntu@your-ec2-public-ip
(You can simply connect using EC2 instance connect )

Step 3: Update the System

  • Update the package lists:

sudo apt update
package updates

  • Upgrade the installed packages:

sudo apt upgrade -y

Step 4: Install Java

  • Install OpenJDK 11:

sudo apt install openjdk-11-jdk -y

java installation

  • Verify the installation:

java -version

Step 5: Install Tomcat

  • Download the latest version of Tomcat:

wget https://downloads.apache.org/tomcat/tomcat-9/v9.0.95/bin/apache-tomcat-9.0.95.tar.gz
**Install tomcat
(see if version is updated)

  • Extract the Tomcat archive:

tar -xvzf apache-tomcat-9.0.95.tar.gz

  • Move the extracted folder to /opt:

sudo mv apache-tomcat-9.0.95 /opt/tomcat

Step 6: Configure Tomcat

  • Add execute permissions to the Tomcat scripts:

sudo chmod +x /opt/tomcat/bin/*.sh

  • Start the Tomcat server:

/opt/tomcat/bin/startup.sh

Step 7: Access Tomcat

Accessing Tomcat

Conclusion

By following these steps, you have successfully installed and configured the Tomcat web application server on an AWS EC2 Ubuntu instance, created a simple Java servlet, and deployed it to Tomcat. You can now develop and deploy more complex Java web applications using this setup.

💖 💪 🙅 🚩
gitgeetansh
Git-Geetansh

Posted on September 18, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related