How to install Tomcat Server 7 on Linux Mint 17.3?

Apache Tomcat™ is an open source software implementation of the Java Servlet, JavaServer Pages, Java Expression Language and Java WebSocket technologies. For more details about you can visit apache official site http://tomcat.apache.org/ .

1. Check your JAVA installation

Java is mandatory to run Apache Tomcat, Use the below command to check whether Java is installed on your system or not.

maro@maro-E7440 ~ $ java -version
java version "1.8.0_74"
Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)

If no, Install OpenJDK or Oracle Java before proceeding Tomcat Installation.

2. Downloading Apache Tomcat Archive file.

Use the this Tomcat 7 link to download the latest stable release of Apache Tomcat 7 Archive file or use the following command to download Tomcat 7.0.68 from Apache server.

maro@maro-E7440 ~ $ cd /opt
maro@maro-E7440 /opt $ sudo wget http://www.us.apache.org/dist/tomcat/tomcat-7/v7.0.68/bin/apache-tomcat-7.0.68.tar.gz

After completed download please extract this archive file in /opt directory. Of course you may change this location depending on your setup.

maro@maro-E7440 $ sudo tar xzf apache-tomcat-7.0.68.tar.gz
maro@maro-E7440 $ sudo mv apache-tomcat-7.0.68 tomcat7

3. Setup Environment Variable.

Before starting Tomcat, Configure environment variables by adding entry in ~/.bashrc file, So that system environment can set on system boot up with the following command.

maro@maro-E7440 $ echo "export CATALINA_HOME=\"/opt/tomcat7\"" >> ~/.bashrc
maro@maro-E7440 $ source ~/.bashrc

4. Start Tomcat.

maro@maro-E7440 /opt $ cd tomcat7/bin
maro@maro-E7440 /opt/tomcat7/bin $ ./startup.sh
Using CATALINA_BASE:   /opt/tomcat7
Using CATALINA_HOME:   /opt/tomcat7
Using CATALINA_TMPDIR: /opt/tomcat7/temp
Using JRE_HOME:        /usr/lib/jvm/java-8-oracle
Using CLASSPATH:       /opt/tomcat7/bin/bootstrap.jar:/opt/tomcat7/bin/tomcat-juli.jar
Tomcat started.

5. Access Apache Tomcat.>

Open your web browser and navigate to http://localhost:8080 or http://your-server-ip-address:8080 or http://127.0.0.1:8080 By default tomcat serving port number 8080 (make sure no other app is running using this port).

6. Setup User Accounts.

If you want to access Server Status, Manager App & Host Manager in tomcat, you need to add manager-gui and admin-gui rols under conf/tomcat-users.xml file.

  • manager-gui : Control Server Status & Manager App
  • admin-gui : Control Host Manager

You can access those things by adding the UserName and password to manager-gui and admin-gui rols (Use your username & password instead of us). Stop tomcat service and add user and roles to your conf/tomcat-users.xml file under tomcat-users then save + exit and start tomcat that’s it.

# user manager can access only manager section.
<role rolename="manager-gui" />
<user username="manager" password="SOME-SECRET-PASSWORD" roles="manager-gui" />

# user admin can access manager and admin section both.
<role rolename="admin-gui" />
<user username="admin" password="SOME-SECRET-PASSWORD_" roles="manager-gui,admin-gui" />

7. Create Tomcat7 Init Script

Create a init file /etc/init.d/tomcat7 using following content. Below you will find my init file for the user maro:

#! /bin/sh
### BEGIN INIT INFO
# Provides: tomcat
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Tomcat
# Description: This file starts and stops Tomcat server
# 
### END INIT INFO

TOMCAT_DIR=/opt/tomcat7/

case "$1" in
 start)
   su maro -c $TOMCAT_DIR/bin/startup.sh
   ;;
 stop)
   su maro -c $TOMCAT_DIR/bin/shutdown.sh
   sleep 10
   ;;
 restart)
   su maro -c $TOMCAT_DIR/bin/shutdown.sh
   sleep 20
   su maro -c $TOMCAT_DIR/bin/startup.sh
   ;;
 *)
   echo "Usage: tomcat {start|stop|restart}" >&2
   exit 3
   ;;
esac

Now execute following commands to set proper permissions and symbolic links for init script.

maro@maro-E7440 $ sudo chmod 755 /etc/init.d/tomcat7
maro@maro-E7440 $ sudo update-rc.d tomcat7 defaults

And it’s DONE!

 

Leave a Reply