I've previously done a guide on the right way of installing Tomcat 5.0 on the Mac but things are a little different on Linux so I figured I'd do another guide. This one is a little less advanced because it only covers running Tomcat as root and not as a non-root user. Depending on how busy I am in the next while I may or may not do a follow-up article on the additional steps needed to run Tomcat as a non-root user. I have tested this procedure on RHEL ES 4 with Tomcat 5.5.17 and the Sun JDK version 1.5.0_6 but it should be the same on all Linux distros and for all 5.X Tomcat versions, the only thing that is likely to change is the location of $JAVA_HOME. Correction, the startup script included is for Redhat based distros only (RHEL, Fedora, CentOS etc).

Before We Begin

Before starting you need to make sure you have the 1.5 version of Sun's JDK installed. If you're on an RPM based Linux install running on x86 the simplest thing to do is to grab the RPM form java.sun.com. How ever you choose to install the Sun JVM you will need to know where it installs to for creating the $JAVA_HOME environment variable later. If you get it from the Sun RPM it will install in /usr/java/ so at the time of writing that means the most current JDK will install to /usr/java/jdk1.5.0_06/. If you are using a Debian based distro (like Ubuntu) you might find my guide on installing the Sun JDK on Debian helpful.

Step 1 - Install Tomcat Files

The first step is to get the binary distribution of Tomcat from the Apache Site (you just need the Core package). When you get this extract it and copy the entire folder it contains to /usr/local. The sequence of commands below assumes that you got the .tar.gz version of the core package for Tomcat 5.5.17. You'll need to adjust slightly for other versions. It is also helpful to create a simlink in /usr/local called tomcat that you will always have pointing at your current tomcat install, makes upgrades easier.

[bbusschots@honeysuckle ~]$ tar -xzf apache-tomcat-5.5.17.tar.gz
[bbusschots@honeysuckle ~]$ sudo mv apache-tomcat-5.5.17 /usr/local/
[bbusschots@honeysuckle ~]$ cd /usr/local/
[bbusschots@honeysuckle local]$ sudo ln -s apache-tomcat-5.5.17/ tomcat

Note: I use sudo for commands that need to be run as root, if your system is not set up to use sudo like this then do everything as root and leave off the sudo from the commands above.

At this point we are basically done. If you want to be able to start and stop tomcat from the command line you'll need to set up environment variables or you can skip that step and set Tomcat up as a service instead. The choice is yours. On a production environment you really should set Tomcat up as a service though.

Step 2a - Setting Environment Variables (Optional):

If you choose to go this route you will need to set the following two environment variables in your shell (because each shell is different I won't go in to how you do that in this article):

  1. JAVA_HOME - needs to point to your Java install. (If you used the latest Sun RPM
    that will be /usr/java/jdk1.5.0_6)
  2. CATALINA_HOME - should be set to /usr/local/tomcat

You are now ready to start Tomcat with the command /usr/local/tomcat/bin/startup.sh and stop Tomcat with the command /usr/local/tomcat/bin/shutdown.sh. Tomcat will not start automatically at boot though.

Step 2b - Setting Tomcat up as a Service (Optional):

If you want Tomcat to start automatically on boot then you need to set it up as a service. To do this you need to copy the code below and save it as a file called tomcat in the folder /etc/init.d:

CODE:
  1. # This is the init script for starting up the
  2. #  Jakarta Tomcat server
  3. #
  4. # chkconfig: 345 91 10
  5. # description: Starts and stops the Tomcat daemon.
  6. #
  7.  
  8. # Source function library.
  9. . /etc/rc.d/init.d/functions
  10.  
  11. # Get config.
  12. . /etc/sysconfig/network
  13.  
  14. # Check that networking is up.
  15. [ "${NETWORKING}" = "no" ] && exit 0
  16.  
  17. tomcat=/usr/local/tomcat
  18. startup=$tomcat/bin/startup.sh
  19. shutdown=$tomcat/bin/shutdown.sh
  20. export JAVA_HOME=/usr/java/jdk1.5.0_6
  21.  
  22. start(){
  23.  echo -n $"Starting Tomcat service: "
  24.  #daemon -c
  25.  $startup
  26.  RETVAL=$?
  27.  echo
  28. }
  29.  
  30. stop(){
  31.  action $"Stopping Tomcat service: " $shutdown
  32.  RETVAL=$?
  33.  echo
  34. }
  35.  
  36. restart(){
  37.   stop
  38.   start
  39. }
  40.  
  41.  
  42. # See how we were called.
  43. case "$1" in
  44. start)
  45.  start
  46.  ;;
  47. stop)
  48.  stop
  49.  ;;
  50. status)
  51.       # This doesn't work ;)
  52. status tomcat
  53. ;;
  54. restart)
  55. restart
  56. ;;
  57. *)
  58. echo $"Usage: $0 {start|stop|status|restart}"
  59. exit 1
  60. esac
  61. exit 0

You may have to change the value for JAVA_HOME if your JDK is in a different location to mine. You then need to make the file executable with the command:

sudo chmod +x /etc/init.d/tomcat

And finally you need to set it to start at boot with the command:

sudo chkconfig --add tomcat

You now have a working Tomcat install that will start it self at boot time. You can also interact with it using the service command to start, stop, restart and see the status of the service at any time. E.g.

sudo service tomcat start
sudo service tomcat satus
sudo service tomcat stop

Comments

27 Responses to “Installing Apache Tomcat 5.5 on Linux”

  1. Bart Busschots » Blog Archive » Installing mod_jk for Apache 1.3 on Mac OS X 10.4 Tiger on November 14th, 2006 4:25 pm

    [...] I’ve done a few previous articles on Apache Tomcat (one for installing it on Linux and one for installing it on OS X), but I haven’t yet mentioned installing the JK Connector (mod_jk) in any environment. For those who are wondering what on earth I’m on about, mod_jk allows the Apache web server to serve your Tomcat web apps so they appear on port 80. There are a number of reasons why you might want to do this. Firstly, it provides a simple and secure way to get Tomcat to respond to requests on port 80 without having to have it run as root. Apache is more efficient at serving static pages so it can help increase the efficiency of your web app, and finally it allows you leverage all the power of Apache’s many features for your Java web app. [...]

  2. suresh bollu on February 20th, 2007 4:44 pm

    its excellent, i serched for this from past one day, finally i find this and my tomcat is working fine now.

  3. Andrew Myers on April 27th, 2007 1:25 am

    Thank you – this is exactly what I was looking for. Saved me a lot of time and headaches!

  4. links for 2007-05-01 « Donghai Ma on May 1st, 2007 6:27 am

    [...] Installing Apache Tomcat 5.5 on Linux : Bart Busschots (tags: linux tips) [...]

  5. Tuong Bi on May 4th, 2007 7:16 am

    very good

  6. Apache Tomcat 5.5 on Ubuntu Edgy Eft 6.10 « munday, tue… on July 27th, 2007 6:06 pm

    [...] Also see http://www.bartbusschots.ie/blog/?p=240 Posted by Ian Munday Filed in Tech, [...]

  7. Setting Tomcat up as a service « munday, tue… on July 27th, 2007 6:28 pm

    [...] from http://www.bartbusschots.ie/blog/?p=240 Posted by Ian Munday Filed in [...]

  8. kabita on September 26th, 2007 10:06 am

    Hello

    I am getting this error while i am doing
    startup.sh

    -bash: /usr/local/tomcat/bin/startup.sh: Permission denied

    i am using fedora core 4 and apache tomcat 6.0.14

    please help me .
    Thanks in advance

  9. Bart B on September 26th, 2007 11:57 am

    Hi Kabita,

    It looks like the permissions on the Tomcat shell scripts have gotten messed up. This can happen if you use the .zip version instead of the .tar.gz version of the download. Just set the permissions using a command like:

    chmod 755 /usr/local/tomcat/bin/*.sh

  10. ranjani on November 29th, 2007 11:37 am

    I have installed tomcat5.5.17 and command sh startup.sh is working.
    But when i give http://localhost:8080 in browser I’m not gettin the index page..But I am getting one default page having some links.. But when i click on that link its giving forbidden.Do not having permission to access this page.. Pls any one can help me?

  11. Lincoln Dickerson on February 1st, 2008 5:05 pm

    Okay I must be missing it but in the set up section you wrote:

    “… To do this you need to copy the code below and save it as a file …”

    Which code below?

    I looked at the HTML and there is a

    which does not seem to be showing up in the blog. Unfortunately I am currently trapped with IE6 which may be the problem.

    Would it be possible for you to email me the source.

    Thank you very much for the article and your time.

    Lincoln

  12. Bart B on February 1st, 2008 5:57 pm

    Hi Lincoln,

    There was a problem with the plugin I was using to include code. I’ve re-added the code so you can see the code now.

    Sorry about that!

    Bart.

  13. Lincoln Dickerson on February 1st, 2008 6:34 pm

    No need post this if you don’t want to. Thanks for the quick response I really appreciate it.

    Did you notice that your blog formating got goofed up when you added in the code sample?

    Have a great day.

  14. KA on February 2nd, 2008 3:26 am

    I got my Tomcat working

  15. laszlo on February 29th, 2008 12:47 pm

    Hi,
    i am from germany, and this is exactly what I was looking for. Saved me a lot of time and headaches!
    Thank You

  16. richard on July 11th, 2008 11:59 pm

    hi there
    this is the most progressive tutorial for tomcat for osx. thanks for that. i got my tomcat starting as shown in my terminal, it is logged on as root:

    /usr/local/tomcat/bin/startup.sh
    Using CATALINA_BASE: /usr/local/tomcat
    Using CATALINA_HOME: /usr/local/tomcat
    Using CATALINA_TMPDIR: /usr/local/tomcat/temp
    Using JRE_HOME: /System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home

    when i go to my browser for http;//localhost:8080 i get the usual:
    Unable to connect

    Firefox can’t establish a connection to the server at localhost:8080.

    what am i doing wrong?
    thanks

  17. richard on July 12th, 2008 12:23 am

    i also tried to get the service working but when i run:

    sudo chkconfig –add tomcat
    sudo: chkconfig: command not found

    what is wrong here as well?
    thanks

  18. Bart B on July 14th, 2008 3:28 pm

    Hi Richard,

    To debug your first problem the best place to start would be to have a look at the logs (they’ll be in the logs folder in the tomcat folder under the localhost directory, you’re looking for catalina.out).

    As for your second problem, it’s either that you’re using a Linux distribution that doesn’t use chkconfig or that your path isn’t configured correctly. The full path to chkconfig should be /sbin/chkconfig so try using that.

    Hope that helps,

    Bart.

  19. Ch le jalle on October 22nd, 2008 4:50 pm

    Thanks a million

    really useful tip to configure apache tomcat at boot time.

  20. bardez on April 3rd, 2009 5:10 am

    Hi, I get the following errors in logs :

    WARNING: error instantiating ‘org.apache.juli.ClassLoaderLogManager’ referenced by java.util.logging.manager, class not found
    java.lang.ClassNotFoundException: org.apache.juli.ClassLoaderLogManager not found
    <>
    WARNING: error instantiating ‘1catalina.org.apache.juli.FileHandler,’ referenced by handlers, class not found
    java.lang.ClassNotFoundException: 1catalina.org.apache.juli.FileHandler,
    <>
    Exception during runtime initialization
    java.lang.ExceptionInInitializerError
    <>
    Caused by: java.lang.NullPointerException
    <>

    I am using RHEL5 with java 1.4 . and apache binary distribution is apache-tomcat-5.5.27.tar.gz. i have also used apache-tomcat-5.5.27-compat.tar.gz

  21. Bart B on April 3rd, 2009 9:40 pm

    Hi bardez,

    Looks like either your Tomcat isn’t properly pointing at your JRE, or that you’re using a third party JRE that’s imperfect. I’ve never had much luck with non-Sun JREs.

    Bart.

  22. claudio on July 10th, 2009 10:23 pm

    i can’t work the following:

    sudo chkconfig –add tomcat

    sudo service tomcat start
    sudo service tomcat satus
    sudo service tomcat stop

    i got debian…

    thanks anyway

  23. devaraj on November 10th, 2009 6:44 am

    Nice.It works fine. But i can see run apache-tomcat.But it doesn’t access admin. What can i do for that accessing admin.It doesn’t work Tomcat Manager(http://localhost:8080/manager/html)..please help me….

  24. devaraj on November 11th, 2009 7:38 am

    Dear sir,
    Already i posted the comments regarding to manage a admin part. This tutorial has helped me a lot.Only thing i cant access the admin part,it shows http 401 error..please help me……….

  25. Kabir on November 14th, 2009 4:40 am

    Hi,
    I Can not work Setup tomcat 5.5 to start Automatically when the system boot. How way I can solve this rooblem.

    Thanks & Regards
    Kabir Al mamun

  26. Bart B on November 14th, 2009 3:01 pm

    Hi Devaraj,

    I don’t use the admin interface. A 401 error indicates that you need to authenticate. I presume you need to set up the admin username and password somewhere. You’ll have to read the Tomcat Documentation though, this is not a feature I use.

    Bart.

  27. Bart B on November 14th, 2009 3:02 pm

    Hi Kabir,

    How you set the auto-start depends on what version of Linux you are using. There is no one answer.

    Bart.

Leave a Reply




Before you post a comment please remember that commenting on my blog is a privilege not a right. I won't approve comments that are obscene, offensive or insulting. For more info please read this post.