Installation of Tomcat 6

Written by Mike on October 16, 2008 – 5:25 pm -

Download and Install JAVA

Download j2sdk-1.4.2 from Sun Download center Here I have used j2sdk-1_4_2_18-linux-i586-rpm.bin which will install j2sdk using RPMS and set the Path of JAVA_HOME automatically

#chmod +x j2sdk-1_4_2_09-linux-i586.bin

Now Check if Java is installed on the server using command java -version

[root@vps907 ~]# java -version
java version “1.6.0_07″
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing)

Download Tomcat

Now Download Tomcat from Apache Website and exract it

#cd /usr/local/
#tar -zxvf apache-tomcat-6.0.18.tar.gz

Create Symlink for the Tomcat Folder

#ln -s /usr/local/apache-tomcat-6.0.18 /usr/local/apache/tomcat

Install Tomcat

#cd apache-tomcat-6.0.18
#cd bin
#tar xvfz jsvc.tar.gz
#cd jsvc-src
#chmod +x configure
#cp jsvc ..
#cd ..

Start Tomcat

Use Following script to start Tomcat Service on the Server


Running Tomcat as non root user

Due to security reasons always run tomcat as non-root user i.e. tomcat. To run it as tomcat first you will have to change the ownership of the tomcat folder

#chown tomcat.tomcat /usr/local/apache-tomcat-6.0.18 -R

Now Tomcat can be stopped and started under user tomcat using following commands:

#su -l tomcat -c /usr/local/apache/tomcat/bin/
#su -l tomcat -c /usr/local/apache/tomcat/bin/

Test Tomcat installation
open a browser and browse website http://xx.xx.xx.xx:8080 where xx.xx.xx.xx will be your Server IP and If you get following output than Tomcat has been installed properly on the Server.

tomcat11 Installation of Tomcat 6

Creating Script to start, stop and restart Tomcat

The above installation step will not create tomcat service so that user can restart tomcat using command service tomcat restart. Create a new file in /etc/init.d as tomcat and copy following contenents into it.

#vi /etc/init.d/tomcat

# Startup script for Tomcat
# chkconfig: 345 84 16
# description: Tomcat
jakarta JSP server
#Necessary environment variables
export CATALINA_HOME=”/usr/local/tomcat”
if [ ! -f $CATALINA_HOME/bin/ ]
echo “Tomcat not available…”

start() {
echo -n -e ‘\E[0;0m'"\033[1;32mStarting Tomcat: \033[0m \n"
su -l tomcat -c $CATALINA_HOME/bin/
touch /var/lock/subsys/tomcatd
sleep 3

stop() {
echo -n -e '\E[0;0m'"\033[1;31mShutting down Tomcat: \033[m \n"
su -l tomcat -c $CATALINA_HOME/bin/
rm -f /var/lock/subsys/tomcatd

status() {
ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start” | awk ‘{printf $1 ” “}’ | wc | awk ‘{print $2}’ > /tmp/tomcat_process_count.txt
read line < /tmp/tomcat_process_count.txt
if [ $line -gt 0 ]; then
echo -n “tomcatd ( pid ”
ps ax –width=1000 | grep “[o]rg.apache.catalina.startup.Bootstrap start” | awk ‘{printf $1 ” “}’
echo -n “) is running…”
echo “Tomcat is stopped”

case “$1″ in
sleep 3
echo “Usage: tomcatd {start|stop|restart|status}”
exit 1

Save and exit from the file. Now assign executable permission to this file

#chown 755 /etc/init.d/tomcat

Enable it for all the Run-levels

#chkconfig –add tomcat
#chkconfig tomcat on

Now you can restart tomcat service using following commands (you can check the screenshot too)

#service tomcat restart <<< To restart tomcat
#service tomcat stop <<< To stop Tomcat
#service tomcat start <<< To start Tomcat
#service tomcat Status <<< to check the status of Tomcat

restart1 Installation of Tomcat 6

Tags: , , , , , ,
Posted in linux, Linux VPS Hosting | 2 Comments »

2 Comments to “Installation of Tomcat 6”

  1. alan sinclair Says:

    Many thanks for the script!. BUT Note that in the script some of the quotes, double-quotes and the dashes before (at least) the second ‘width’ command have been changed into non-ASCII characters, and have to be fixed before the script will work.

  2. hello world | steve hulet Says:

    [...] 4) from [...]

Leave a Comment


  • Subscribe Me

  • Tag Cloud

  • Archives