A Step by Step Guide to Installing Apache Tomcat 9 Linux
Apache Tomcat is an open-source Java Servlet Container developed by Apache Software Foundation that is used to run Java applications. This container runs applications that are written in Java, and its primary purpose is to create a Java web server that is capable of hosting Java-based web applications. In this article, we will provide a step-by-step guide on how to install Apache Tomcat 9 Linux.
Step 1: Update your System
The first thing you should do is update your system to ensure that all of the packages you’ll need are up-to-date. To do this, open the terminal and enter the following command:
sudo apt-get update
Step 2: Install Java
Apache Tomcat 9 requires Java to be installed on your server. If you don’t have a Java installed, you’re going to want to install one.
sudo apt-get install default-jre
Alternatively, you can install the OpenJDK version:
sudo apt-get install openjdk-8-jdk
Step 3: Download Apache Tomcat 9
Now that Java is downloaded and installed, you can proceed to download the latest version of Tomcat. You can do this simply by visiting the official Apache Tomcat 9 web page and copy the link to the hyperlink next to the Linux tar.gz Binary.
wget https://downloads.apache.org/tomcat/tomcat-9/v9.0.50/bin/apache-tomcat-9.0.50.tar.gz
Step 4: Extract the Tar.gz Archive
Once the download of the Tomcat 9 binary is complete, extract the tar.gz file to the opt directory (/opt/) using the tar command.
sudo tar -zxvf apache-tomcat-9.0.50.tar.gz -C /opt/
Step 5: Set the Variable
To access Tomcat from your local web browser, you need to set some environment variables such as JAVA_HOME, CATALINA_HOME, and some others.
Use the Nano editor to edit the environment file.
sudo nano /etc/environment
After that, set the environment variables as shown below:
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
JRE_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre
CATALINA_HOME=/opt/apache-tomcat-9.0.50
CATALINA_BASE=/opt/apache-tomcat-9.0.50
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$CATALINA_HOME/bin
Step 6: Create Admin User
By default, no user has admin access to your Tomcat server, which is recommended for security purposes. To create an admin user, create a tomcat-users.xml file in the /opt/apache-tomcat-9.0.50/conf directory and add the following lines to it.
sudo nano /opt/apache-tomcat-9.0.50/conf/tomcat-users.xml
Step 7: Launch Apache Tomcat 9
To launch the Tomcat server, execute the following command:
sudo sh /opt/apache-tomcat-9.0.50/bin/startup.sh
Step 8: Access Tomcat from Web Browser
Now that the Tomcat server is running, you can access it from any web browser by entering:
http://your_server_IP:8080
You will be prompted for the admin user credentials that you created earlier. Once you enter the login information, you will be directed to the Tomcat Administration page.
Conclusion
By following the above guide, you can now install and run Apache Tomcat 9 on your Linux machine. Apache Tomcat is one of the most popular Java application servers globally and is an excellent choice for web application deployment.