How to install Apache Tomcat in Ubuntu

This post will describe how to install and configure Apache Tomcat. Apache Tomcat is a Servlet Container for Java-based Web Application. It is an open source software developed by Apache Software Foundation.
It has three major Components
  • Catalina (Servlet Container)
  • Coyote (HTTP connector)
  • Jasper (JSP engine)
Software Version used in this post were as follows:
Tomcat v9.08, Ubuntu 18.04 and Java JDK
Step 1  Install Java
Step 2 Create Tomcat User
Step 3 Install Tomcat
Step 4 Configure Tomcat
Step 5 Manage Credentails
Step 6 Start Tomcat
-----------------------------------
STEP 1 : INSTALLING JAVA
If Java JDK is not available install it.
First, update the package index
$ sudo apt-get update
Then install Java JDK
$ sudo apt-get install default-jdk

STEP 2 : CREATE TOMCAT USER
Create new tomcat group
$ sudo groupadd tomcat
 Create tomcat user with a home directory where we can install tomcat(/opt/tomcat)
$ sudo useradd -s /bin/false -g groupname -d directory location
$ sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat

STEP 3 : INSTALL TOMCAT
use
$ sudo mkdir /opt/tomcat
$ wget http://www-eu.apache.org/dist/tomcat/tomcat-9/v9.0.10/bin/apache-tomcat-9.0.10.tar.gz
$ sudo tar xzvf apache-tomcat-9*tar.gz -C /opt/tomcat --strip-components=1

STEP 4 : CONFIGURE TOMCAT
$ cd /opt/tomcat
$  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/
$ sudo update-java-alternatives -l
copy the location
$ sudo nano /etc/systemd/system/tomcat.service
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target

[Service]
Type=forking

Environment=JAVA_HOME=paste the copied path
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
save the file
$ sudo systemctl daemon-reload
$ sudo systemctl start tomcat
$ sudo systemctl status tomcat
$ sudo ufw allow 8080
STEP 5 : MANAGE CREDENTIALS
$ sudo nano /opt/tomcat/conf/tomcat-users.xml
<tomcat-users . . .>
    <user username="admin" password="password" roles="manager-gui,admin-gui"/>
</tomcat-users>
save and close
$ sudo systemctl restart tomcat

Comments

  1. thank u bro. it works for me

    ReplyDelete
  2. I am unable to login with my credentials. I followed the steps exactly, but it did not work for me. Can any one please help me

    ReplyDelete
    Replies
    1. What is the problem? Is there a problem with login? Give the credentials configured in the tomcat-users.xml.

      Delete
  3. -r -m -U -d also please update on these cmd

    ReplyDelete
  4. At the time of download it shows Error 404 Not Found as I am using the internet over proxy.
    Please suggest me the solution.

    ReplyDelete
    Replies
    1. Try this link
      http://www-eu.apache.org/dist/tomcat/tomcat-9/v9.0.24/bin/apache-tomcat-9.0.24.tar.gz

      Delete
  5. If you're seeing this page via a web browser, it means you've setup Tomcat successfully. Congratulations!

    This is the default Tomcat home page. It can be found on the local filesystem at: /var/lib/tomcat8/webapps/ROOT/index.html

    Tomcat8 veterans might be pleased to learn that this system instance of Tomcat is installed with CATALINA_HOME in /usr/share/tomcat8 and CATALINA_BASE in /var/lib/tomcat8, following the rules from /usr/share/doc/tomcat8-common/RUNNING.txt.gz.

    You might consider installing the following packages, if you haven't already done so:

    tomcat8-docs: This package installs a web application that allows to browse the Tomcat 8 documentation locally. Once installed, you can access it by clicking here.

    tomcat8-examples: This package installs a web application that allows to access the Tomcat 8 Servlet and JSP examples. Once installed, you can access it by clicking here.

    tomcat8-admin: This package installs two web applications that can help managing this Tomcat instance. Once installed, you can access the manager webapp and the host-manager webapp.

    NOTE: For security reasons, using the manager webapp is restricted to users with role "manager-gui". The host-manager webapp is restricted to users with role "admin-gui". Users are defined in /etc/tomcat8/tomcat-users.xml.

    ReplyDelete
  6. Nice articel, This article help me very well. Thank you. Also please check my article on my site Know All About Htaccess Tutorial. In link article we will learn about How to use .htaccess file?.

    ReplyDelete

Post a Comment

Popular posts from this blog

How to install MRTG on UBUNTU

How to mine cryptocurrency using unMineable