Howto Install Tomcat on Linux ?

Dec-19th-2008

# Download and Install JAVA

Download j2sdk-<version> from Sun Download center http://developers.sun.com/downloads/

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

Now set java home path

# vi .bash_profile

JAVA_HOME=/usr/local/j2sdk

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

[root@map ~]# 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 extract it

http://tomcat.apache.org/download-55.cgi

# cd /usr/local/
#wget http://www.poolsaboveground.com/apache/tomcat/tomcat-6/v6.0.18/bin/apache-tomcat-6.0.18.tar.gz
# 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
# ./configure
# make
# cp jsvc ..
# cd ..

Now set Cataline home path

# vi .bash_profile

CATALINA_HOME=/usr/loca/tomcat

JAVA=/usr/loca/j2sdk/bin

Save and exit

# Type following commands

# export JAVA_HOME=/usr/local/j2sdk

# export JAVA=/usr/local/j2sdk/bin

# export CATALINA=/usr/local/tomcat

# Start Tomcat

Use Following script to start Tomcat Service on the Server

# /usr/local/apache/tomcat/bin/startup.sh

# 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 -R tomcat.tomcat /usr/local/apache-tomcat-6.0.18

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

# su -l tomcat -c /usr/local/apache/tomcat/bin/startup.sh
# su -l tomcat -c /usr/local/apache/tomcat/bin/shutdown.sh

# 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 Tomcat page than Tomcat has been installed properly on the Server.

# 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

#!/bin/bash

#
# 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/catalina.sh ]
then
echo “Tomcat not available…”
exit
fi

start() {
echo -n -e ‘\E[0;0m'"\033[1;32mStarting Tomcat: \033[0m \n"
su -l tomcat -c $CATALINA_HOME/bin/startup.sh
echo
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/shutdown.sh
rm -f /var/lock/subsys/tomcatd
echo
}

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
else
echo “Tomcat is stopped”
fi
}

case “$1? in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 3
start
;;
status)
status
;;
*)
echo “Usage: tomcatd {start|stop|restart|status}”
exit 1
esac

Now 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.

# 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

Now you have successfully installed Tomcat.

====================================================================

Enjoy Linux !!!


Mega World News Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google Yahoo Buzz StumbleUpon Weekend Joy

Comments

  1. p-root Said,

    You are such a good friend of linux lovers………………….

    Thanks
    p-root :)

  2. Bokudan Said,

    Good and clear linux manual about tomcat and linux , thankx!

  3. Timur Alhimenkov Said,

    Good work! Thank you very much!
    I always wanted to write in my blog something like that. Can I take part of your post to my blog?
    Of course, I will add backlink?

    Sincerely, Timur I. Alhimenkov

  4. Agervesheetry Said,

    Hi there

    If anyone knows or provide..

    I need UK VPN account.. (to bypass unblock etc..)

    I already have USA vpn account..

    I dont want to provide vpn service..

    I want to buy and enjoy one..

  5. Map007 Said,

    Hi,

    We don’t provide UK VPN ……………

    Sorry for that.

  6. mark Said,

    It is the coolest site,keep so!

  7. mark Said,

    thanks !! very helpful post!

  8. Tamiflu Said,

    Incredible site!

  9. cialis Said,

    Great topic. Now i can say thank you

  10. javagame Said,

    Very goood!!!

  11. pills Said,

    Nice work

  12. pills Said,

    Great site. Keep doing

  13. online Said,

    thank you for this

  14. buypills Said,

    Nice blog! Very interesting themes

  15. buypills Said,

    Very interesting theme

  16. dadies Said,

    nice job men:)

  17. indian Said,

    It is the coolest site, keep so

  18. gaybdsm Said,

    Awesome!

  19. femdom Said,

    Thx

  20. feetblog Said,

    thank you soooooo much for this

  21. shemales Said,

    AWESOME! Great job.

  22. teen Said,

    thx!. This one is great!!!

  23. schoolgirl Said,

    Thank you very much!
    Regards!!

  24. piyush Said,

    Hi,

    http://www.linuxjournal.com/article/8561

  25. mp3 Said,

    Perfect site, i like it!

  26. музыка Said,

    Lots of Good information in your posting, I bookmarked your blog post so I can visit again in the near future, Cheers

  27. seolace Said,

    Nice post, thanks for writing!

  28. Linux Surgeon » Blog Archive » Tomcat with Apache Integration ? Said,

    [...] Tomcat with Apache Integration ? Dec-21st-2008 By piyushmap in Tomcat TweetHow to install Tomcat on Fedora | CentOS | RedHat [...]

Add A Comment

*