"How to Install Tomcat 9 on Ubuntu 20.04" - MS TV Life.COM September, 2020
How to Install Tomcat 9 on Ubuntu 20.04

“How to Install Tomcat 9 on Ubuntu 20.04”

“How to Install Tomcat 9 on Ubuntu 20.04”

We hope this post helped you to find out  “How to Install Tomcat 9 on Ubuntu 20.04”

This tutorial describes how one can set up and configure Tomcat 9 on Ubuntu 20.04.

Apache Tomcat is an open-source internet server and Java servlet container. It is among the hottest selections for constructing Java-based web sites and functions. Tomcat is light-weight, straightforward to make use of, and has a sturdy ecosystem of add-ons.

Installing in Java #

Tomcat 9 requires Java SE eight or later to be put in on the system. We’ll set up OpenJDK 11, the open-source implementation of the Java Platform.

Run the next instructions as root or consumer with sudo privileges or root to replace the packages index and set up the OpenJDK 11 JDK bundle:

sudo apt update
sudo apt install openjdk-11-jdk

As soon as the set up is full, confirm it by checking the Java model:

java -version

The output should look something like this:

openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)

Making a System Person #

Working Tomcat beneath the basis consumer is a safety danger. We’ll create a brand new system consumer and group with residence listing /decide/tomcat that may run the Tomcat service. To take action, enter the next command:

sudo useradd -m -U -d /opt/tomcat -s /bin/false tomcat

Downloading Tomcat #

Tomcat binary distribution is obtainable for obtain from the Tomcat downloads page.

On the time of writing, the most recent Tomcat model is 9.0.35. Earlier than persevering with with the subsequent step, verify the Tomcat 9 obtain web page to see if a more recent model is obtainable.

Use wget to obtain the Tomcat zip file to the /tmp listing:

VERSION=9.0.35 wget https://www-eu.apache.org/dist/tomcat/tomcat-9/v${VERSION}/bin/apache-tomcat-${VERSION}.tar.gz -P /tmp

Once the download is complete, extract the tar file to the /opt/tomcat directory::

sudo tar -xf /tmp/apache-tomcat-${VERSION}.tar.gz -C /opt/tomcat/

Tomcat is up to date frequently with safety patches and new options. To have extra management over variations and updates, we’ll create a symbolic hyperlink known as newest, that factors to the Tomcat set up listing:

sudo ln -s /opt/tomcat/apache-tomcat-${VERSION} /opt/tomcat/latest

Later, when upgrading Tomcat, unpack the newer model and alter the symlink to level to it.

The system consumer that was beforehand created will need to have entry to the tomcat set up listing. Change the directory ownership to consumer and group tomcat:

sudo chown -R tomcat: /opt/tomcat

The shell scripts inside the Tomcat’s bin directory must be executable:

sudo sh -c 'chmod +x /opt/tomcat/latest/bin/*.sh'

These scripts are used to start, stop and, otherwise manage the Tomcat instance.

Creating SystemD Unit File #

Instead of using the shell scripts to start and stop the Tomcat server, we’ll set it to run as a service.

Open your text editor and create a tomcat.service unit file in the /etc/systemd/system/ directory:

sudo nano /etc/systemd/system/tomcat.service

Paste the following configuration:

/etc/systemd/system/tomcat.service
[Unit]
Description=Tomcat 9 servlet container
After=network.target

[Service]
Type=forking

User=tomcat
Group=tomcat

Environment="JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom -Djava.awt.headless=true"

Environment="CATALINA_BASE=/opt/tomcat/latest"
Environment="CATALINA_HOME=/opt/tomcat/latest"
Environment="CATALINA_PID=/opt/tomcat/latest/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"

ExecStart=/opt/tomcat/latest/bin/startup.sh
ExecStop=/opt/tomcat/latest/bin/shutdown.sh

[Install]
WantedBy=multi-user.target

Modify the JAVA_HOME variable if the path to your Java installation is different.

Save and close the file and notify systemd that a new unit file exists:

sudo systemctl daemon-reload

Enable and start the Tomcat service:

sudo systemctl enable --now tomcat

Check the service status:

sudo systemctl status tomcat

The output should show that the Tomcat server is enabled and running:

● tomcat.service - Tomcat 9 servlet container
     Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2020-05-25 17:58:37 UTC; 4s ago
    Process: 5342 ExecStart=/opt/tomcat/latest/bin/startup.sh (code=exited, status=0/SUCCESS)
   Main PID: 5362 (java)
...

You can start, stop and restart Tomcat same as any other systemd service:

sudo systemctl start tomcat
sudo systemctl stop tomcat
sudo systemctl restart tomcat

Configuring Firewall #

In case your server is protected by a firewall and also you wish to entry Tomcat from the surface of your native community, you’ll want to open port 8080.

Use the next command to open the required port:

sudo ufw allow 8080/tcp

Typically, when operating Tomcat in a manufacturing setting, you need to use a load balancer or reverse proxy. It’s a finest follow to permit entry to port 8080 solely out of your inside community.

Configuring Tomcat Internet Administration Interface #

At this level, you need to be capable to entry Tomcat with an online browser on port 8080. The online administration interface shouldn’t be accessible as a result of we now have not created a consumer but.

Tomcat customers and roles are outlined within the tomcat-users.xml file. This file is a template with feedback and examples exhibiting how one can create a consumer or function.

On this instance, we’ll create a consumer with “admin-gui” and “manager-gui” roles. The “admin-gui” function permits the consumer to entry the /host-manager/html URL and create, delete, and in any other case handle digital hosts. The “manager-gui” function permits the consumer to deploy and undeploy internet utility with out having to restart your complete container by the /host-manager/html interface.

Open the tomcat-users.xml file and create a brand new consumer, as proven beneath:

sudo nano /opt/tomcat/latest/conf/tomcat-users.xml
/opt/tomcat/latest/conf/tomcat-users.xml
<tomcat-users>
<!--
    Comments
-->
   <role rolename="admin-gui"/>
   <role rolename="manager-gui"/>
   <user username="admin" password="admin_password" roles="admin-gui,manager-gui"/>
</tomcat-users>

Be sure to change the username and password to one thing safer.

By default, Tomcat internet administration interface is configured to permit entry to the Supervisor and Host Supervisor apps solely from the localhost. To entry the online interface from a distant IP, you’ll have to take away these restrictions. This may occasionally have varied safety implications, and it’s not really useful for manufacturing methods.

To allow entry to the online interface from wherever, open the next two information and remark or take away the strains highlighted in yellow.

For the Supervisor app:

sudo nano /opt/tomcat/latest/webapps/manager/META-INF/context.xml

For the Host Manager app:

sudo nano /opt/tomcat/latest/webapps/host-manager/META-INF/context.xml
context.xml
<Context antiResourceLocking="false" privileged="true" >
<!--
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127.d+.d+.d+|::1|0:0:0:0:0:0:0:1" />
-->
</Context>

If you want to access the web interface only from a specific IP, instead of commenting the blocks add your public IP to the list.

Let’s say your public IP is 41.41.41.41 and you want to allow access only from that IP:

context.xml
<Context antiResourceLocking="false" privileged="true" >
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127.d+.d+.d+|::1|0:0:0:0:0:0:0:1|41.41.41.41" />
</Context>

The list of allowed IP addresses is a list separated with vertical bar |. You can add single IP addresses or use a regular expressions.

Once done, restart the Tomcat service for changes to take effect:

sudo systemctl restart tomcat

Test the Tomcat Installation #

Open your browser and type: http://<your_domain_or_IP_address>:8080

Assuming the installation is successful, a screen similar to the following should appear:

apache tomcat 7.0,
tomcat support, 
tomcat web application manager, 
apache tomcat latest version, 
tomcat 7 ssl, 
tomcat configuration file, 
tomcat container, 
tomcat server 7 download, 
tomcat webapps, 
tomcat server configuration, 
tomcat admin url, 
install tomcat 7,
tomcat 6.0,
How to Install Tomcat 9 on Ubuntu 20.04,

Tomcat web application manager is available at: http://<your_domain_or_IP_address>:8080/manager/html.

apache tomcat 7.0,
tomcat support, 
tomcat web application manager, 
apache tomcat latest version, 
tomcat 7 ssl, 
tomcat configuration file, 
tomcat container, 
tomcat server 7 download, 
tomcat webapps, 
tomcat server configuration, 
tomcat admin url, 
install tomcat 7,
tomcat 6.0,
How to Install Tomcat 9 on Ubuntu 20.04,

Tomcat virtual host manager is available at: http://<your_domain_or_IP_address>:8080/host-manager/html.

apache tomcat 7.0,
tomcat support, 
tomcat web application manager, 
apache tomcat latest version, 
tomcat 7 ssl, 
tomcat configuration file, 
tomcat container, 
tomcat server 7 download, 
tomcat webapps, 
tomcat server configuration, 
tomcat admin url, 
install tomcat 7,
tomcat 6.0,
How to Install Tomcat 9 on Ubuntu 20.04,

Conclusion #

We’ve proven you how one can set up Tomcat 9.Zero on CentOS eight and how one can entry the Tomcat administration interface.

For extra details about Apache Tomcat, go to the official documentation page.

We hope the “How to Install Tomcat 9 on Ubuntu 20.04” help you. If you have any query regarding “How to Install Tomcat 9 on Ubuntu 20.04″drop a comment below and we will get back to you at the earliest.

We hope this post helped you to find out  “How to Install Tomcat 9 on Ubuntu 20.04”  . You may also want to see – How to Install Anaconda on CentOS 8

Copy link
Powered by Social Snap