Now that you have set up your AWS site (such as this site that you are on), you may want to add extra features, such as running Java Web Services in the background.
This guide will explain on how you can safely install and use Apache Tomcat on the preconfigured Bitnami WordPress image you have selected when you signed up for a free AWS account.
Before you proceed, you need to have
- A running AWS EC2 instance with Bitnami WordPress image installed
- Basic knowledge in Linux (if you don’t have knowledge, it’s fine as long as you follow this guide)
- You must be currently logged in to your AWS instance via SSH
- Root credentials (the highest possible credentials for ease)
The steps to install Apache Tomcat on your Bitnami WordPress AWS instance is summarized below. You have two options in installing Java: you can install Java the easy way, or you can install Java the hard way. Both methods are described below.
Bitnami WordPress AWS images are based on Ubuntu. If you are familiar in using Ubuntu Servers, this guide will be very easy for you. Since this guide is designed to be read by amateurs, the detailed step in installing Apache Tomcat is described below.
Step 1 (Option 1): Install Java the easy way
Before you get started with everything, you need to execute everything as the root user. You can do this by running the following command (copy and paste the command after the dollar $ symbol):
$ sudo su
After that, the dollar symbol ($) will change into the sharp (#) symbol. This means you now have root privileges. Then, you need to update your the package index of your Bitnami WordPress AWS instance. Since this instance is based on Ubuntu, you can run the following command:
# apt-get update
You can then proceed installing Java Development Environment by running the following:
# apt-get install default-jdk
After this, you can confirm which version of Java is installed in your system by running:
# java -version
Step 1 (Option 2): Installing Java from Oracle Source
Here, we will be installing Java using the files provided by Oracle.
IMPORTANT! Please take note that this procedure will install Java in the following location:
If you wish to install it at some other location(or if you think that Java should be located elsewhere), you may do so.
Sub-step 1: Download Java from Oracle
To start, you should first get the download link from Oracle. First you should visit the following site using a web browser:
In that page, you will see the latest version of Java.
At the command prompt, first go to the directory shown above:
# cd /opt/bitnami
If the folder java hasn’t been created yet, you can type
# mkdir /opt/bitnami/java
Then access that folder:
# cd /opt/bitnami/java
Now that you have the download link of Oracle’s Java, you will be able to download this file at the terminal using the wget command:
# wget [download-link]
You should paste the download link after the command wget.
You can confirm that you downloaded the file completely by comparing the file sizes at the Oracle Download Page and the file you have just downloaded by executing:
# ls -l –block-size=MB
When you use wget, the file will be saved in some random filename, so it would be best to rename the downloaded file to some user friendly name. We do so by
# mv [downloaded-file-name] java.tar.gz
Hint: You don’t have to type the very long filename of the file you have just downloaded. You can first type the first letters of the filename and then press the TAB key to use the terminal’s auto-complete feature
Sub-step 2: Install Java
Again, it is assumed that you are currently working at the following location:
Now that you have renamed the file after downloading it, it’s time to unpack this tar.gz archive:
# tar zxvf java.tar.gz
You will know that Java has been successfully installed after you have seen the command prompt once again:
Sub-step 3: Set Oracle JDK as the default JVM
In this guide, the current version of Java SDK was 9.0.4. We’ll use this for convenience. You may choose to change the version number to indicate the version of Java you have downloaded. You may execute:
# update-alternatives /usr/bin/java java /opt/bitnami/java/jdk-9.0.4/bin/java 100
# update-alternatives --install /usr/bin/javac javac /opt/bitnami/java/jdk-9.0.4/bin/javac 100
After executing both commands, you should be able to see no error. You should be able to see the terminal waiting for a command, just like this:
Sub-step 4: Verify your installation of Java
You can verify that you have successfully installed Java by executing
update-alternatives --display java
update-alternatives --display javac
You will be able to see the same message such as the one below:
Step 2: Install Tomcat
It is assumed that you are working at the directory /opt/bitnami/java because of Step 1b above. We will be working with the directory /opt/bitnami, so change to that directory:
# cd /opt/bitnami
To install tomcat, there are two steps involved. These sub-steps are described below.
Sub-step 1: Create Tomcat user and user group
For your own data security, a separate tomcat user and tomcat user group should be created.
First, create the tomcat user group:
# groupadd tomcat
Then, create tomcat’s home folder:
# mkdir /opt/bitnami/tomcat
After that, we can proceed with the creation of tomcat user:
# useradd -s /bin/nologin -g tomcat /opt/bitnami/tomcat
You have just finished created the user tomcat that belongs to the user group tomcat, and this user cannot log in using the terminal.
Sub-step 2: Download the latest version of Tomcat
To download Tomcat, you need to first get the latest version and the download link. You can do this by visiting Apache Tomcat’s site using your favorite browser. When this guide was written, the latest version was 9.0.5. We’ll use that version.
To download Tomcat, execute this wget command:
# wget http://apache.mirror.cdnetworks.com/tomcat/tomcat-9/v9.0.5/bin/apache-tomcat-9.0.5-deployer.tar.gz
Once you have downloaded Tomcat, you can proceed the installation:
# tar -zxvf apache-tomcat-9.0.5-deployer.tar.gz -C /opt/bitnami/tomcat --strip-components=1
You have successfully installed Apache Tomcat.
Sub-step 3: Update permissions
Before you can run tomcat whenever your server starts, we need to update some file permissions first.
Go to the directory where we installed tomcat:
# cd /opt/bitnami/tomcat
After that, give the user group tomcat permissions to this folder:
# sudo chgrp -R tomcat
(To be continued…)