Setting Up Apache Tomcat 9 on an AWS Ubuntu Instance: A Comprehensive Installation Guide



Introduction

In the dynamic landscape of web development, Apache Tomcat stands as a robust and widely-used application server. This comprehensive guide walks you through the process of setting up Apache Tomcat 9 on an AWS Ubuntu instance, ensuring a smooth installation for your web applications.

Prerequisites:

Before we embark on the installation journey, ensure you have the following prerequisites in place:

  • An active AWS account
  • An Ubuntu instance launched and accessible
  • Basic knowledge of the terminal/command line

Step 1: Connect to Your Ubuntu Instance

Start by connecting to your AWS Ubuntu instance using SSH. Use a tool like PuTTY (for Windows users) or the terminal on macOS/Linux. Make sure you have the necessary permissions to install and configure software on the instance.


Step 2: Update and Upgrade Packages

Keep your system up to date by running the following commands:

  • Command : sudo apt update
  • Command : sudo apt upgrade

Step 3: Install Java

Tomcat 9 requires Java to operate. Install the OpenJDK package with the following command

  • Command : sudo apt install default-jdk




Check the installed Java version to verify the installation:

  • Command : java -version




Step 3:Download and Extract Apache Tomcat 9

Visit the official Apache Tomcat website (https://tomcat.apache.org/download-90.cgi) and copy the download link for the latest version. On your Ubuntu instance, use the following commands to download and extract Tomcat 9:

  • Command : tar -xzvf apache-tomcat-9.0.83.tar.gz



Step 5: Move Tomcat to a Preferred Location

Move the extracted Tomcat directory to a location of your choice. For example:

  • Command : sudo mv apache-tomcat-9.0.83 /opt/tomcat


Note :

Moving the extracted Tomcat directory to a preferred location is an optional step, but it's a recommended best practice for organizational purposes and to adhere to standard directory structures. Placing Tomcat in a specific directory, such as /opt/tomcat, helps keep your file system tidy and makes it easier to manage the Tomcat installation.

By moving it to a dedicated directory like /opt/tomcat, you create a clear separation between your Tomcat installation and other system files. This can be especially beneficial when dealing with multiple software installations or when collaborating with other developers who may need to locate or modify Tomcat-related files.

If you choose not to move Tomcat to a preferred location, you can keep it in the directory where it was initially extracted. However, keep in mind that this may result in a less organized file structure, and you'll need to adjust subsequent instructions accordingly.

In the provided installation guide, the recommendation to move Tomcat to /opt/tomcat is made for clarity and consistency, but it's not a mandatory step. You can adapt the instructions based on your preferences and organizational practices.


Step 6: Configure Environment Variables

To enable system-wide access to Tomcat, set up environment variables by editing the .bashrc file:

  • Command : echo 'export CATALINA_HOME="/opt/tomcat"' >> ~/.bashrc
  • Command : source ~/.bashrc


Step 7: Start Tomcat

Navigate to the Tomcat bin directory and initiate the server:

  • Command : cd /opt/tomcat/bin
  • Command : ./startup.sh

Verify that Tomcat is running by accessing the default Tomcat page using your instance's public IP address and port 8080 in a web browser.

Conclusion:

With Apache Tomcat 9 successfully installed on your AWS Ubuntu instance, you now have a powerful foundation for hosting and deploying Java-based web applications. Explore the extensive documentation provided by Tomcat for further customization and optimization to meet your specific project requirements.