May
22
Installing Apache Tomcat 5.5 on Linux
Filed Under Computers & Tech, System Administration on May 22, 2006 at 2:15 pm
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):
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
)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
:
# This is the init script for starting up the # Jakarta Tomcat server # # chkconfig: 345 91 10 # description: Starts and stops the Tomcat daemon. # # Source function library. . /etc/rc.d/init.d/functions # Get config. . /etc/sysconfig/network # Check that networking is up. [ "${NETWORKING}" = "no" ] && exit 0 tomcat=/usr/local/tomcat startup=$tomcat/bin/startup.sh shutdown=$tomcat/bin/shutdown.sh export JAVA_HOME=/usr/java/jdk1.5.0_6 start(){ echo -n $"Starting Tomcat service: " #daemon -c $startup RETVAL=$? echo } stop(){ action $"Stopping Tomcat service: " $shutdown RETVAL=$? echo } restart(){ stop start } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) # This doesn't work ;) status tomcat ;; restart) restart ;; *) echo $"Usage: $0 {start|stop|status|restart}" exit 1 esac 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
[…] 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. […]
its excellent, i serched for this from past one day, finally i find this and my tomcat is working fine now.
Thank you – this is exactly what I was looking for. Saved me a lot of time and headaches!
[…] Installing Apache Tomcat 5.5 on Linux : Bart Busschots (tags: linux tips) […]
very good
[…] Also see http://www.bartbusschots.ie/blog/?p=240%5D Posted by Ian Munday Filed in Tech, […]
[…] from http://www.bartbusschots.ie/blog/?p=240%5D Posted by Ian Munday Filed in […]
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
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
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?
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
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.
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.
I got my Tomcat working
Hi,
i am from germany, and this is exactly what I was looking for. Saved me a lot of time and headaches!
Thank You
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
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
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.
Thanks a million
really useful tip to configure apache tomcat at boot time.
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
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.
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
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….
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……….
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
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.
Hi Kabir,
How you set the auto-start depends on what version of Linux you are using. There is no one answer.
Bart.
Dear all
thanks for all, it is very useful comment about installing apache tomcat.
Originally attempted the yum install tomcat5 on a RHEL5 box. Couldn’t get it to work.
Followed your instructions with Tomcat 5.5.28, Java JDK 1.6.0_18. Works great! Thank you.
Many thanks,
I appreciate. You made my job much easier.
Cheers
Siddharth
The best write-up I found for what should be a simple task. Thanks.
very good!!!!!!!!!!!!!!
Thanks for nice, simple way for setting this up. I had this up and running in a couple of minutes. (Only thing is that cut-and-paste from the web page introduced a “.” character instead of ” (not sure why).