How to Install Apache Tomcat 9 on Ubuntu 18.04

Reading Time: 3 minutes

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.

Pre-flight
  • 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 18.04 server

Step 1: Install or Verify Java 8 is installed

java -version

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

java -versionOutput:

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)

 

Step 2: Install Tomcat 9

wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.8/bin/apache-tomcat-9.0.8.tar.gz

 

Step 3: Extract Tomcat 9 Tarball

However, fun to think about, this tarball doesn’t belong to any cat, it belong to Tomcat!  We’ll be moving this tarball into the /opt/tomcat directory.

mkdir /opt/tomcat

mv apache-tomcat-9.0.8.tar.gz /opt/tomcat

tar -xvzf /opt/tomcat/apache-tomcat-9.0.8.tar.gz

 

Step 4: 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.

groupadd tomcat

useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat

 

Step 5: 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

cd /opt/tomcat/apache-tomcat-9.0.8

chmod -R g+r conf

chmod g+x conf

chown -R tomcat webapps/ work/ temp/ logs/

 

Step 6: Create a Systemd Service File

Copy the path of Tomcat’s home by running this command:

update-java-alternatives -lOutput:
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).

vim /etc/systemd/system/tomcat.service

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.

 

[Unit] Description=Apache Tomcat
After=syslog.target network.target
[Service] Type=forking
Environment=JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64
Environment=CATALINA_PID=/opt/tomcat/apache-tomcat-9.0.8/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat/apache-tomcat-9.0.8
Environment=CATALINA_BASE=/opt/tomcat/apache-tomcat-9.0.8
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'
WorkingDirectory=/opt/tomcat/apache-tomcat-9.0.8
ExecStart=/opt/tomcat/apache-tomcat-9.0.8/bin/startup.sh
ExecStop=/opt/tomcat/apache-tomcat-9.0.8/bin/shutdown.sh
User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always
[Install] WantedBy=multi-user.target

Be sure to save the file by using :wq

 

Step 7: Reload the Systemd File

We do this so the system can recognize the changes to the file that we just edited.

systemctl daemon-reload

Step 8: Restart Tomcat

systemctl start tomcat

Note:
If the Tomcat service fails to start use journalctl -xn as a way to know the exact errors that are occurring.

 

Step 9: Verify Tomcat is Running

systemctl status tomcat

Output:

* 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)
CGroup: /system.slice/tomcat.service
`-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.

 

An Introduction to Managing a Linux Server with systemd

Reading Time: 2 minutes

Systemd is is an init system used by several common Linux Distributions which has gained popularity since 2015. A Linux init system is the first process or daemon started on a system after the initial boot process, and manages services, daemons, and other system processes. Systemd is comprised of unit files that contain the initialization instructions for the daemons which it controls. While many portions of a system can be managed with systemd, this article will focus on managing services. Continue reading “An Introduction to Managing a Linux Server with systemd”

How to Install and Configure vsftpd on CentOS 7

Reading Time: 2 minutes

FTP (File Transfer Protocol) is one of the most popular methods to upload files to a server. There exist a wide array of FTP servers, such as vsftpd, you can use and FTP clients exist for every platform.

Essentially no matter what OS you use you can find an easy to use FTP client, so it makes for a great solution to transfer files. On CentOS based servers before you can connect via FTP you’ll have to setup an FTP server. Here we’re gonna setup vsftpd which is a great option since it has a focus on security and speed.

Continue reading “How to Install and Configure vsftpd on CentOS 7”

Change a Password for PostgreSQL on Linux via Command Line

Reading Time: 1 minute

PostgreSQL supports many client authentication methods, but in this case we’re only going to concern ourselves with two: password and md5.

Note: The default authentication method for PostgreSQL is ident. If you’d like to change the PostgreSQL authentication method from ident to md5, then visit the linked tutorial!

Continue reading “Change a Password for PostgreSQL on Linux via Command Line”

Change PostgreSQL Authentication Method from Ident to MD5

Reading Time: 2 minutes

PostgreSQL supports multiple client authentication methods including: trust, reject, md5, password, gss, sspi, krb5, ident, peer, ldap, radius, cert, and pam. Here we’re only going to concern ourselves with two: ident and md5.

Continue reading “Change PostgreSQL Authentication Method from Ident to MD5”

What is the Default Password for PostgreSQL?

Reading Time: 1 minute

When connecting to PostgreSQL on Linux for the first time many admins have questions, especially if those admins are from the MySQL world. By default, when PostgreSQL is installed, a postgres user is also added.

If you run the command:

cat /etc/passwd

… you’ll see the postgres user.

Continue reading “What is the Default Password for PostgreSQL?”

How to Install and Connect to PostgreSQL on Fedora 22

Reading Time: 1 minute

PostgreSQL (pronounced ‘post-gres-Q-L’) is a free, open-source object-relational database management system (object-RDBMS), similar to MySQL, and is standards-compliant and extensible. It is often used as a back-end for web and mobile applications. PostgreSQL, or ‘Postgres’ as it is nicknamed, adopts the ANSI/ISO SQL standards together, with the revisions.

Pre-Flight Check

  • These instructions are intended specifically for installing PostgreSQL on Fedora 22.
  • I’ll be working from a Liquid Web Self Managed Fedora 22 server, and I’ll be logged in as root.

Continue reading “How to Install and Connect to PostgreSQL on Fedora 22”

How to Install and Configure VSFTPD on Fedora 22

Reading Time: 2 minutes

FTP (File Transfer Protocol) is probably the most popular method of uploading files to a server; a wide array of FTP servers, such as vsftpd, and clients exist for every platform.

Pre-Flight Check

  • These instructions are intended specifically for installing the vsfptd on Fedora 22.
  • I’ll be working from a Liquid Web Self Managed Fedora 22 server, and I’ll be logged in as root.

Continue reading “How to Install and Configure VSFTPD on Fedora 22”

How To Install MySQL / MariaDB on Fedora 22

Reading Time: 1 minute

MariaDB is a drop-in replacement for MySQL. It is easy to install, offers many speed and performance improvements, and is easy to integrate into most MySQL deployments. Answers for compatibility questions can be found at: MariaDB versus MySQL – Compatibility. MariaDB offers more storage engines than MySQL, including Cassandra (NoSQL), XtraDB (drop-in replacement for InnoDB), and OQGRAPH.

Pre-Flight Check

  • These instructions are intended for installing MariaDB on a single Fedora 22 node.
  • I’ll be working from a Liquid Web Self Managed Fedora 22 server, and I’ll be logged in as root.

Continue reading “How To Install MySQL / MariaDB on Fedora 22”

How to Start and Enable Firewalld on Fedora 22

Reading Time: 1 minute
It is highly recommended that you have a firewall protecting your server.

Pre-Flight Check

  • These instructions are intended specifically for enabling and starting firewalld on Fedora 22.
  • I’ll be working from a Liquid Web Self Managed Fedora 22 server, and I’ll be logged in as root.

Continue reading “How to Start and Enable Firewalld on Fedora 22”