blog.itcode.devblog.itcode.dev

[Raspberry Pi 4] Installing Tomcat on Ubuntu

Now that the OS is ready, let's build out the web server environment in earnest. We'll use Tomcat, a representative WAS, to host pages.

[Raspberry Pi 4] Installing Tomcat on Ubuntu

Now that the OS is ready, let's build out the web server environment in earnest. We'll use Tomcat, a representative WAS, to host pages.
RWB0104
@RWBwritten at 2021-09-02 14:07:19
Raspberry Pi

시리즈 모아보기

Raspberry Pi

3 / 7

Now that the OS is ready, let's build out the web server environment in earnest. We'll use Tomcat, a representative WAS, to host pages.

  • Tomcat 9.0.50

Let's build a web server on the Ubuntu server through the following process.

The WAS we'll use is Tomcat, and running it requires a WAS runtime.

BASH

sudo apt-get install openjdk-15-jdk

Install the JAVA version you want. In this post, we install the latest version, JAVA 15.

BASH

java -version

OUTPUT

openjdk version "15.0.3" 2021-04-20
OpenJDK Runtime Environment (build 15.0.3+3-Ubuntu-1)
OpenJDK 64-Bit Server VM (build 15.0.3+3-Ubuntu-1, mixed mode, sharing)

If running the java -version command outputs a result in this format, the JAVA installation is complete.

Set the JAVA environment variables. Check the path of the file actually invoked when you run the javac Java compiler command, to find the installation path.

BASH

which javac

OUTPUT

/usr/lib/jvm/java-15-openjdk-arm64/bin/javac

The which command finds the location of a command. Entering it to check the location produces a path like the one above. It's installed in a folder like java-{VERSION}-openjdk-arm64, and the folder name varies slightly by version.

The above path is not a folder, but the path of the command file itself. JAVA_HOME is /usr/lib/jvm/java-15-openjdk-arm64, the top-level path where Java is installed.

Set the environment variable in the user config file, .profile.

BASH

vi ~/.profile

INPUT

export JAVA_HOME=/usr/lib/jvm/java-15-openjdk-arm64
export PATH=$JAVA_HOME/bin:$PATH

Open the user config file and enter the content above. You can enter edit mode by pressing a or i. Once you're done, type :wq to save.

BASH

source ~/.profile

Enter the above command to reload the changed user config file. Without doing this, the changed environment variables won't take effect in that shell.

BASH

sudo apt-get install tomcat9
sudo apt-get install libtcnative-1

tomcat9 is Tomcat version 9, and installing the libtcnative-1 package lets you activate Tomcat Native without compiling anything.

If you search for Tomcat Native, you may come across commands like ./configure and make — those refer to compiling the Tomcat Native module directly, so keep that in mind for reference.

Tomcat's installation path is /var/lib/tomcat9.

BASH

 # Start Tomcat
systemctl start tomcat9

 # Stop Tomcat
systemctl stop tomcat9

 # Restart Tomcat
systemctl restart tomcat9

You can turn the Tomcat service on/off with the commands above.

You can check whether Tomcat Native is activated in the logs; if a message like the one above appears in the log, Tomcat Native is activated.

BASH

cd /var/log/tomcat9

For Tomcat9, the logs are in this directory, and you can check them by opening a file in the format catalina.yyyy-MM-dd.log.

Open the port to be used for communication.

Ubuntu makes it easy to manage firewall settings with ufw.

BASH

sudo apt-get install ufw

You can install ufw with the above command.

BASH

 # Enable ufw
sudo ufw enable

 # Disable ufw
sudo ufw disable

 # Check ufw status
sudo ufw status verbose

Since ufw is disabled by default after installation, activate it with the sudo ufw enable command.

Since Tomcat uses 8080 as its default port, open that port.

BASH

sudo ufw allow 8080

Configuring a firewall with ufw
On Ubuntu, you can easily configure a firewall using ufw, and you can check how to use it in this post.

BASH

ifconfig -a

Entering the above command shows the connected IP, but if you're using a router, a private IP like 192.168.0.x will be shown. In that case, check your router settings for the actual incoming IP.

  • eth0 - Ethernet info
  • wlan0 - Wireless LAN info

Depending on the internet connection method, they're distinguished as above. If multiple are connected via the same method, the number increases by 1 each time.

Access the Raspberry Pi's IP at xxx.xxx.xxx.xxx:8080 and check whether the Tomcat page displays correctly.

If you haven't changed any settings, the admin page above should be displayed.

If it doesn't display correctly, check the following items.

  • Whether the internet connection is normal
  • Whether the IP connected to the Raspberry Pi is correct
  • Whether the Tomcat service port is open
  • Whether Tomcat is running properly
  • Set up an Ubuntu server on the Raspberry Pi.
  • Run Tomcat to host pages.
  • Apply a domain.
  • Set up remote communication environments such as SSH and RDP.
  • Install MariaDB to handle DB communication.
# Raspberry Pi# Ubuntu# Domain
ship
blog.itcode.dev

Notes from the π-th Alpaca

7.0.1
Developed by RWB since 2021.057th upgraded at 2026.08