The Apache Tomcat software is an open source which helps to run Java Servlet, JavaServer Pages, Java Expression Language and Java Web-socket technologies. For your better understanding apache tomcat is a web server that serves JSP pages.

    Apache Tomcat is trademark of the Apache Software Foundation.

    In this articles we are going to install Apache Tomcat through source file on /usr/local/ directory. Where we going to run our web server. The default port for Apache Tomcat is 8080.

    Installing from source used to be very common and also quite simple. You would download the source file, unpack it (with either zip or tar), then issue the commands to the the directory you want to install it.

Requirements to Run Apache Tomcat server:

    Java to be installed, There is a single requirement for Apache tomcat that is, your server should be installed with Java or JDK.

Installing Java:

    We are going to install the Oracle JDK through apt-get, which is the official version distributed by Oracle, you will need to follow a few more steps.

Adding the Repository:

    First, add Oracle's PPA, then update your package repository.

$ add-apt-repository ppa:webupd8team/java

$ apt-get update

Then, depending on the version you want to install, use the following commands:

For JDK 8,

    For Java 8 use the following command,

$ apt-get install oracle-java8-installer

For JDK 9,

    For Java 9 use the following command,

$ apt-get install oracle-java9-installer

    You can also install different version of Java according to your requirements. Click here for setting up it.

Installing Tomcat:

1.Downloading the source package:

Get the source file for the desired version from the official website of Apache, where you can find the latest version. click here to download latest package

You can either download or wget the file (tar.gz and zip are available for Linux).

$ wget http://mirrors.estointernet.in/apache/tomcat/tomcat-9/v9.0.13/bin/apache-tomcat-9.0.13.zip

2.Unzip and Renaming the package:

$ unzip apache-tomcat-9.0.13.zip

Either you can rename the unzipped folder to tomcat or create a symlink as tomcat.

$ mv apache-tomcat-9.0.13 tomcat

3. Addig user and group for tomcat:

    We are going to create an user(non-logging account) and a group for tomcat.

$ groupadd tomcat

$ useradd -s /bin/nologin -g tomcat -d /usr/local/tomcat tomcat

Providing access to the user and group:

    To access the files the, user and group should have proper permissions.

$ cd /usr/local/tomcat
$ chgrp -R tomcat conf
$ chmod g+rwx conf
$ chmod g+r conf/*
$ chown -R tomcat logs/ temp/ webapps/ work/
$ chgrp -R tomcat bin
$ chgrp -R tomcat lib
$ chmod g+rwx bin
$ chmod g+rx bin/*

4.Setting up the Java Environment for Tomcat:

    Export the Java and CATALINA path as follows,

$ export JAVA_HOME=/usr/lib/jvm/jre
$ export PATH=$PATH:/usr/lib/jvm/jre
$ export CATALINA_PID=/usr/local/tomcat/tomcat.pid
$ export CATALINA_HOME=/usr/local/tomcat
$ export CATALINA_BASE=/usr/local/tomcat


    The default conf for Apache Tomcat is /usr/local/tomcat/conf/server.xml
   
    The default document path for Apache Tomcat is /usr/local/tomcat/webapps.  All your java files are maintained here.

    We will be seeing how to run virtual hosts in Apache Tomcat on the upcoming articles.

5.Adding a Web Management Interface:

    We need to create an admin user for your Tomcat server to use the "Host manager" and the "Manager App" through the web interface.

Edit the tomcat-users.xml file,

$ vim /usr/local/tomcat/conf/tomcat-users.xml

    Add the below line inside the <tomcat-users> module to define a admin user,

<user username="UserName" password="Password123" roles="manager-gui,admin-gui"/>

    Save the file.

6. Start the Tomcat application:

    Now you have all set to run a Tomcat server. Start the application using the below commands.

$ /usr/local/tomcat/bin/startup.sh

    For your note use shutdown.sh to stop the process.

$ /usr/local/tomcat/bin/shutdown.sh

    After starting the tomcat enter the IP of the server or 127.0.0.1( if it is installed in local system) with the port 8080 on your browser. You can view the Tomcat default page on your browser.

    Log into the "Manager App" or "Host manager" using the credentials that you have provided on the tomcat-users.xml file.

    Now you have successfully installed and configured customized Apache Tomcat on your system.



    For Tomcat-8, Tomcat-7 and older versions click here.

    Feel free to ask if you have any questions.

Comments

  1. Be the first to add a comment.