Steps to Install Tomcat in CentOS

In this tutorial we can learn how to install Tomcat on a CentOS server.

Install JDK

1) Execute following to the command line for Install Java SE Development Kit (JDK7) and build Java Environment.

$ curl -LO -H “Cookie: oraclelicense=accept-securebackup-cookie” \

http://download.oracle.com/otn-pub/java/jdk/7u75-b13/jdk-7u75-linux-x64.rpm

2) Install downloaded rpm package.

$ rpm -Uvh jdk-7u75-linux-x64.rpm

3) Open /etc/profile and add the following to the configuration file.

$ vi /etc/profile

export JAVA_HOME=/usr/java/default

export PATH=$PATH:$JAVA_HOME/bin

exportCLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/li$JAVA_HOME/lib/tools.jar

4) Run the following command.

$ source /etc/profile

5) You can create a test program to check its working normally. In here we are taking a file “example.java”

$ vi example.java

(You can add any java test program to the example.java file)

6) After adding test program, you need to execute following command.

$ javac example.java

$ compile

$ java example

$ execute

 

Install tomcat

1) Download tomcat package.

$ wget http://ftp.riken.jp/net/apache/tomcat/tomcat-7/v7.0.73/bin/apache-tomcat-7.0.73.tar.gz

2) Extract tar file.

$ tar -xf apache-tomcat-7.0.59.tar.gz

3) Move the file.

$ mv tomcat-7.0-doc /usr/tomcat7

4) Add a user.

$ useradd -M -d /usr/tomcat7 tomcat

5) Change the ownership.

$ chown -R tomcat. /usr/tomcat7

6) Create a tomcat init script.

Open /etc/rc.d/init.d/tomcat and add the following to the file.

$ vi /etc/rc.d/init.d/tomcat7

#!/bin/bash

# Tomcat7: Start/Stop Tomcat 7

# chkconfig: – 90 10

# description: Tomcat is a Java application Server.

 

. /etc/init.d/functions

. /etc/sysconfig/network

 

CATALINA_HOME=/usr/tomcat7

TOMCAT_USER=tomcat7

 

LOCKFILE=/var/lock/subsys/tomcat7

 

RETVAL=0

start(){

echo “Starting Tomcat7: ”

su – $TOMCAT_USER -c “$CATALINA_HOME/bin/startup.sh”

RETVAL=$?

echo

[ $RETVAL -eq 0 ] && touch $LOCKFILE

return $RETVAL

}

 

stop(){

echo “Shutting down Tomcat7: ”

$CATALINA_HOME/bin/shutdown.sh

RETVAL=$?

echo

[ $RETVAL -eq 0 ] && rm -f $LOCKFILE

return $RETVAL

}

 

case “$1″ in

start)

start

;;

stop)

stop

;;

restart)

stop

start

;;

*)

echo $”Usage: $0 {start|stop|restart}”

exit 1

;;

esac

exit $?

7) Assign permission to the init file.

$ chmod 755 /etc/rc.d/init.d/tomcat7

8) Execute following command to start tomcat service.

$ /etc/rc.d/init.d/tomcat7 start

Now tomcat installation has been successfully finished. You can access tomcat from your browser with port 8080:

If you need any further assistance please contact our support department.

Was this answer helpful? 0 Users Found This Useful (0 Votes)