Installing and Accessing Tomcat Web-App server in EC2 server
Git-Geetansh
Posted on September 18, 2024
Prerequisites
- AWS Account: Ensure you have an active AWS account.
- EC2 Instance: Launch an Ubuntu EC2 instance.
- Security Group: Configure the security group to allow inbound traffic on port 22 (SSH) and port 8080 (Tomcat).
- SSH Client: Have an SSH client like PuTTY or terminal for connecting to your EC2 instance.
- Java Development Kit (JDK): Ensure you have JDK installed on your local machine for compiling Java code.
Safety Best Practices
- Use IAM Roles: Assign an IAM role to your EC2 instance for secure access to AWS services.
- Security Groups: Restrict access to your EC2 instance by configuring security group rules.
- Regular Updates: Keep your system and software up to date with the latest security patches.
- 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.
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:
- Upgrade the installed packages:
sudo apt upgrade -y
Step 4: Install Java
- Install OpenJDK 11:
sudo apt install openjdk-11-jdk -y
- 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
**
(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
- Open your web browser.
- Navigate to http://your-ec2-public-ip:8080.
- You should see the Tomcat welcome page.
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.
Posted on September 18, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.