Apache Tomcat is an accessible, open-source application server used to house many of today applications. It’s free, stable, lightweight and is utilized to render Java coding as well a range of other applications.
Today we will be focusing on how to install Apache Tomcat 9 on our Liquid Web Ubuntu server, specifically Ubuntu 18.04 LTS.
- Open the terminal and log in as root. If you are logged in as another user, you will need to add sudo before each command.
- Working on a Linux Ubuntu VPS server
Install or Verify Java 8 is installed
If nothing is returned or you get the message “No such file or directory” then you’ll need to install Java 8.
In this case, we’ll be installing OpenJDK 8 because it’s free and, the OracleJDK recently reached its EOL in January 2019.
apt install default-jdk -y
If Java was installed successfully, you’d see something like this when using the java -version command
openjdk version "10.0.2" 2018-07-17
OpenJDK Runtime Environment (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4)
OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4, mixed mode)
Install Tomcat 9
Extract Tomcat 9 Tarball
However, fun to think about, this tarball doesn’t belong to any cat, it belongs to Tomcat!
We’ll be moving this tarball into the /opt/tomcat directory.
mv apache-tomcat-9.0.8.tar.gz /opt/tomcat
tar -xvzf /opt/tomcat/apache-tomcat-9.0.8.tar.gz
Create a Tomcat user
We create the tomcat user as extra security as this user will be the one who has group ownership to the Tomcat files.
useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat
Update permissions to Tomcat
Since Tomcat belongs to the group category, we have to update the permission for some of the directories of Tomcat.
chgrp -R tomcat /opt/tomcat
chmod -R g+r conf
chmod g+x conf
chown -R tomcat webapps/ work/ temp/ logs/
Create a Systemd Service File
Copy the path of Tomcat’s home by running this command:
java-1.11.0-openjdk-amd64 1101 /usr/lib/jvm/java-1.11.0-openjdk-amd64</b
Your path may look different but, that’s alright, take the highlighted path and put it into your /etc/systemd/system/tomcat.service file, as the JAVA_HOME variable (shown below).
Just as the path may look different from our example, you’ll focus on providing the variables in this file the path to our Tomcat installation(a.k.a. Tomcat’s root directory). For example, we’ll let the server know that the startup.sh and shutdown.sh files are located in the /bin directory of Tomcat. At any rate, be sure that your paths (bolded in the example) are the correct paths.
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Be sure to save the file by using :wq
Reload the Systemd File
We do this so the system can recognize the changes to the file that we just edited.
systemctl start tomcat
Verify Tomcat is Running
systemctl status tomcat
* tomcat.service - Apache Tomcat
Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2019-04-04 14:33:04 EDT; 4min 29s ago
Process: 10912 ExecStart=/opt/tomcat/apache-tomcat-9.0.8/bin/startup.sh (code=exited, status=0/SUCCESS)
Main PID: 10930 (java)
Tasks: 47 (limit: 2157)
`-10930 /usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/java -Djava.util.logging.config.file=/opt/tomcat/apache-tomcat-9.0.8/conf/logging.properties -Djava.util.logging.manage
If correctly installed you’ll also be able to see the Tomcat default page by visiting http://Host_IP:8080 in your browser, replacing Host_IP with your server’s IP or hostname, followed by Tomcat’s port number 8080.
The Most Helpful Humans In Hosting™
We pride ourselves on being The Most Helpful Humans In Hosting™! Our support staff is always available to assist with any Dedicated, Cloud, or VPS server issues 24 hours a day, 7 days a week 365 days a year.
We are available, via our ticketing systems at email@example.com, by phone (at 800-580-4986) or via a LiveChat for whatever method you prefer. We work hard for you so you can relax.