On this tutorial we will discuss how to install Apache Tomcat 9.0.41 on Linux Ubuntu 20.04 LTS operating system.
Apache Tomcat is an open-source of Java technology implementation. Tomcat is one of the most popular choices for building Java-based websites and applications. There are several Java technology namely : Java Servlet, JavaServer Pages, Java Expression Language and WebSocket technologies. On this tutorial we will discuss how to install the last stabel version of Apache Tomcat on Linux Ubuntu 20.04 LTS operating system. The last stable of Apache Tomcat is version 9.0.41 which was released on 8, 2020.
The Apache Tomcat installation wil be consist of several steps, namely :
- root or user with sudo privilege
- Java installed on the system
- Apache Tomcat installation on Ubuntu 20.04 LTS
- Configuring Apache Tomcat
- Configuring Firewall
- Access Web Interface
Before the Apache Tomcat installation process begins, we must prepare several requirements, namely:
- having root or an ordinary user with
- Java installed on the system, Apache Tomcat requires Java runtime to run properly on the system. We will query the java version installed to make sure if Java was installed by submitting command line : java –version.
ramans@diginet-app02:~$ java -version openjdk version "22.214.171.124" 2020-11-04 OpenJDK Runtime Environment (build 126.96.36.199+1-Ubuntu-0ubuntu1.20.04) OpenJDK 64-Bit Server VM (build 188.8.131.52+1-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)
If our system has no Java installed yet, just install it fires. For Java installation on Ubuntu 20.04 LTS can be found on this article.
On this tutorial, we will use the latest stable Apache Tomcat, version 9.0.41 which has been available official Apache Tomcat download page.
Before Apache Tomcat installation is starting, we will update our Ubuntu 20l.04 LTS system first, by submitting command line :
sudo apt update.
ramans@diginet-app02:~$ sudo apt update [sudo] password for ramans: Hit:1 http://us.archive.ubuntu.com/ubuntu focal InRelease Get:2 http://security.ubuntu.com/ubuntu focal-security InRelease [109 kB] Get:3 http://us.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
We need a non root user to run the Tomcat service for security and management purpose, called as
tomcat. We will create a new system user with
/opt/tomcat as his default directory.
ramans@diginet-app02:~$ sudo useradd -m -U -d /opt/tomcat -s /bin/false tomcat [sudo] password for ramans:
On this section we will download Apache Tomcat 9.0.41, extract it and creating systemd service. We will download the latest Apache Tomcat source located which is located at the
https://downloads.apache.org/tomcat/tomcat-9/v9.0.41/src/apache-tomcat-9.0.41.tar.gz by using
wget command line.
ramans@diginet-app02:~$ sudo mkdir /opt/tomcat ramans@diginet-app02:~$ wget https://downloads.apache.org/tomcat/tomcat-9/v9.0.41/bin/apache-tomcat-9.0.41.tar.gz --2021-01-09 07:05:34-- https://downloads.apache.org/tomcat/tomcat-9/v9.0.41/bin/apache-tomcat-9.0.41.tar.gz Resolving downloads.apache.org (downloads.apache.org)… 184.108.40.206, 2a01:4f8:10a:201a::2 Connecting to downloads.apache.org (downloads.apache.org)|220.127.116.11|:443… connected. HTTP request sent, awaiting response… 200 OK Length: 11442169 (11M) [application/x-gzip] Saving to: ‘apache-tomcat-9.0.41.tar.gz’ apache-tomcat-9.0.41.tar.gz 100%[============================================>] 10.91M 765KB/s in 19s 2021-01-09 07:05:54 (600 KB/s) - ‘apache-tomcat-9.0.41.tar.gz’ saved [11442169/11442169]
On this step, we will extract the source file to
ramans@diginet-app02:~$ sudo tar xzvf apache-tomcat-9.0.41.tar.gz -C /opt/tomcat --strip-components=1 [sudo] password for ramans: apache-tomcat-9.0.41/conf/ apache-tomcat-9.0.41/conf/catalina.policy apache-tomcat-9.0.41/conf/catalina.properties
After Tomcat binary files are extracted then we have to set the right permission on their files under
sudo chgrp -R tomcat /opt/tomcat sudo chmod -R g+r conf sudo chmod g+x conf sudo chown -R tomcat webapps/ work/ temp/ logs/
On this section, we will create Apache Tomcat systemd file and activate it as a service. Create a file under
/etc/systemd/system directory and name it as tomcat.service. Verify and make sure the JAVA_HOME with the path of our Java installation. The conten of its file is as follow :
ramans@diginet-app02:~$ cd /etc/systemd/system ramans@diginet-app0[2:/etc/systemd/system$ sudo vi /etc/systemd/system/tomcat.service sudo] password for ramans:
[Unit] Description=Apache Tomcat Web Application Container After=network.target [Service] Type=forking Environment=JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64 Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid Environment=CATALINA_HOME=/opt/tomcat Environment=CATALINA_BASE=/opt/tomcat Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC' Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom' ExecStart=/opt/tomcat/bin/startup.sh ExecStop=/opt/tomcat/bin/shutdown.sh User=tomcat Group=tomcat UMask=0007 RestartSec=10 Restart=always [Install] WantedBy=multi-user.target
After tomca.service file was created, then we reload the service on our sever system, and start the tomcat service and verify if the service is running properly.
ramans@diginet-app02:/etc/systemd/system$ sudo systemctl daemon-reload ramans@diginet-app02:/etc/systemd/system$ sudo systemctl start tomcat ramans@diginet-app02:/etc/systemd/system$ sudo systemctl status tomcat ● tomcat.service - Apache Tomcat Web Application Container Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2021-01-09 09:28:53 PST; 1min 10s ago Process: 68356 ExecStart=/opt/tomcat/bin/startup.sh (code=exited, status=0/SUCCESS) Main PID: 68363 (java) Tasks: 30 (limit: 9451) Memory: 138.8M CGroup: /system.slice/tomcat.service └─68363 /usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/java -Djava.util.logging.config.file=/opt/tomca> Jan 09 09:28:53 diginet-app02 systemd: Starting Apache Tomcat Web Application Container… Jan 09 09:28:53 diginet-app02 startup.sh: Tomcat started. Jan 09 09:28:53 diginet-app02 systemd: Started Apache Tomcat Web Application Container. ramans@diginet-app02:/etc/systemd/system$ sudo vi opt/tomcat/conf/tomcat-users.xml ramans@diginet-app02:/etc/systemd/system$ sudo vi /opt/tomcat/conf/tomcat-users.xml ramans@diginet-app02:/etc/systemd/system$
After the Apache Tomcat service is running properly, then we need to configure it as suitable with our application need. For doing this, we need to access the Apache Tomcat web portal which is by default binding on port 8080. To access and use the Apache Tomcat web app manager, we need to login to the server. To setup username and password we have to edit the
ramans@diginet-app02:/opt/tomcat$ sudo vi /opt/tomcat/conf/tomcat-users.xml [sudo] password for ramans:
Then we update the file with these entries :
If our server is located inside a firewall system, then we have to allow traffic from any source to port 8080 of the our Tomcat Server. By default Tomcat is running on port 8080, So we need to open port 8080 to allow connections.
This is the last section on how to install Apache Tomcat on Ubuntu 20.04 LTS article. On this section we will test the Apache Tomcat server. By using browser we can open external IP address followed by port 8080.
On this case we will use http://192.168.19.137:8080.
So far, we have installed Apache Tomcat 9.0.41. on Ubuntu 20.04 LTS operating system successfully. For further exploration about Apache Tomcat, just go to Apache Tomcat official web. Have a nice day… stay safe, stay at home.