I’m not very smart on installing packages on Linux, but today I need to configure a Tomcat on a CentOS 5.2. The CentOS 5.2 has Tomcat 5 available as yum package, with gcc-java. But Java gurus tell me to use the original Sun JDK to run Tomcat without problems. I know that Tomcat can run with a JRE which is a lot smaller, so I started with download the Java JRE 6 Update 11 from here. I choosed Linux/Multilanguage and accepted the Sun Terms. I downloaded the jre-6u11-linux-i586.bin file wich is an autoinstaller for Linux. After uploading the file in the /root dir, I did a chmod to make the file executable: chmod u+x jre-6u11-linux-i586.bin and then ran it


I needed to accept the long legal stuff by Sun, inputing a “yes” at the end of the text (press spacebar many time to reach the end). I got the jre folder that I have to move into /usr or something. Not really satisfying me. Why not to try with an rpm, always from the Sun download page? The file is called jre-6u11-linux-i586-rpm.bin. Make it executable, run it (as the previous file), accept the legal stuff and you have an rpm which will be automatically installed. The JRE will e installed in:


Now it’s time form Tomcat 5. I used the version 5.5.26, not the latest 5.5.27: we have problem with some JSP containing XML fragments which wouldn’t compile. Tomcat 5 can be download from the archives: pick the file apache-tomcat-5.5.26.tar.gz. Moved it on /root I gunzipped it:

gunzip apache-tomcat-5.5.26.tar.gz

and then untared (I know Linux guru, all those thing can e done with a single compact command line, but it take more time to read the man pages compared to run two separate and clear commenads).

tar xvf apache-tomcat-5.5.26.tar

I got the apache-tomcat-5.5.26 folder which I moved to /usr/tomcat. I like the simple things and not the hyper parametric future minded configurations…

mv apache-tomcat-5.5.26 /usr/tomcat

Now I need some script to run Tomcat as a deamon to put in /etc/init.d. I found a page (which i lost…) and modified the script to match my path. Pay attention: I need Tomcat to run on port 80, so I made it to run as root. If you want to make it run as another user (like tomact) but still responding on port 80, either you need to put in front of it Apache or add some (for me) strange rules to iptables.

The script can be downloaded here: [download id=”13″]

The file needed to be copied in /etc/init.d, and then

chown root:root /etc/init.d/tomcat

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

To install the script for various runlevels, I ran

/sbin/chkconfig –add tomcat

it will be marked as “on” for runlevel 3, 4, 5 (I’m interest in rulevel 5). To see the configuration of all services, you can run

/sbin/chkconfig –list

On my server Apache was installed and running and I need to stop it to free the port 80. So I marked it as “off” for every runlevel:

/sbin/chkconfig httpd off

and then I stopped it:

/etc/init.d/httpd stop

Now it’s time to configure and then try to run Tomcat. Firstly I changed the configuration


to make it listen to the port 80. Find the string port=”8080″ and change it to port=”80″. Easy. To run Tomcat has to be configured with the Java path. Remember we are using a JRE so we need to set the environement variable JRE_HOME (not the JAVA_HOME). I did it creating the file “setenv.sh” in /usr/tocat/bin. This file is used by startup and shutdown scripts, without modify them or the catalina.sh script (this is a good practice for future Tomcat upgrade). The file content will be:

export JRE_HOME=/usr/java/latest export CATALINA_PID=/var/run/tomcat.pid The CATALINA_PID variable force Tomcat to create the pid file of the process, useful to kill it. Note that a shutdown of Tomcat can be done in two way. With the call:


the same call made from our deamon script, or

/usr/tomcat/bin/shutdown -force

which make the script to wait a little and if the process doesn’t terminate it will be killed (using the pid). You can modify the deamon script to shutdown with “force” (I do it everytime). To start and stop Tomcat:

/etc/init.d/tomcat start

/etc/init.d/tomcat stop

My excuses for my bad english but it's the only way I have to communicate with you. Would you suggest a correction? Leave a comment, thank you!


Charles Bryan · December 10, 2012 at 2:05 pm

Thanks !!! Appreciate it…

tina · April 5, 2012 at 10:19 am

Thank you so much for this! You really explain things and not only post lines of commands so this is really helpful!

But I have to install a specific version of tomcat6 – do you have any idea if the script you linked works with tomcat6, too?

Nathan · November 17, 2011 at 1:53 am

Thank! really helped me out

Manny · November 8, 2011 at 10:17 pm

First off, thank you for the article.
I will be going over it and consuming it in detail shortly.
But coming from an IIS background (from 4.0 to 7.5) my first reaction is… really? …Wow..umm ok.
It just seems really high touch and archaic.
Maybe I am missing the elegance. Time will tell I suppose.

daniele · September 22, 2011 at 2:56 pm

if [[ `ps auxww | grep tomcat | grep -v grep | grep -c java` -gt 0 ]]
echo “Tomcat is running with pid: `ps auxww | grep tomcat | grep -v grep | grep java | awk ‘{ print $2 }’`”
echo “PID does not exist. Tomcat is stopped”

Keuka Lake Real Estate · September 12, 2011 at 6:56 pm

This information was very helpful.

Kunal sagar · June 28, 2011 at 9:32 am

Thanks a lot!!!

ivansh · June 27, 2011 at 6:56 pm

Nice article, quite helpful.

Sandy · June 26, 2011 at 2:11 pm

My VPS Configuration
OS: centos-5-x86_64
VPS Platform: OpenVZ
HDD : 50 GB
Ram : 1 GB

I am trying to install 1 software on my VPS. But java is giving me some problem

[property] java.io.IOException: Cannot run program “/bin/env”: java.io.IOException: error=12, Cannot allocate memory

So then I am tried to allocate heap memory to JVM by using command
# java -Xms128m -Xmx128m DoRunTime

It will give such type of error

Exception in thread “DoRunTime” java.lang.NoClassDefFoundError: DoRunTime
Caused by: java.lang.ClassNotFoundException: DoRunTime

I am install JAVA using Command # yum install java-1.6.0-openjdk-devel

I have set my JAVA_PATH=/usr/lib/jvm/java-1.6.0-openjdk-

Also I have set my CLASSPATH=/usr/lib/jvm/java-1.6.0-openjdk-

Also is there need to set PATH???
I Don’t know what is going wrong.

Giuseppe Frattura · June 21, 2011 at 11:13 am

Thank you this post is very useful, helped me to set up my application on a remote dedicated server.

Melak · June 19, 2011 at 1:42 pm


When I entered the command usr/tomcat/bin/shutdown.sh i get the permission denied error. How to solve this problem?

I’m in CentOS 5.5

uki · May 2, 2011 at 5:48 pm

You should never run tomcat as a root user. It’s very dangerous. Apache is a good choice, and there’s a few connectors:

mod_jk is mature, stable and extremely flexible.. It is under active development by members of the Tomcat community.

mod_proxy. A cheap way to proxy without the hassles of configuring JK. If you don’t need some of the features of jk – this is a very simple alternative.

    Stefano · May 6, 2011 at 2:36 pm

    A simple iptable rule can let tomcat to run on port 8080 (for example) but respond on port 80, so one can use it without apache if he have no resource to manage a frontend web server too.

SergioT · April 8, 2011 at 8:41 pm

Something to check, the correct place of server.xml is:


Christian · March 19, 2011 at 9:21 pm

Man… running tomcat as a ROOT… you gotta be crazy man :D

Ilan · February 25, 2011 at 4:00 am

Great stuff! Much appreciated.

Ubezzi · February 15, 2011 at 1:59 am


jitendra · February 13, 2011 at 4:36 pm

Thanks a lot! really moving towards OpenSource community..

Alan · February 8, 2011 at 9:34 pm

when i type

/etc/init.d/httpd stop

return [FAILED]

so cant continue

btw, good tutorial!

Crypto · January 17, 2011 at 8:11 am

don’t run tomcat as root in a production environment. trust me on this.

Gonzalo · October 25, 2010 at 11:54 pm

Thank you!

at · May 7, 2010 at 5:05 pm

small thing that I noticed, that the command for adding tomcat into chkconfig is:

/sbin/chkconfig –add tomcat

Just do /sbin/chkconfig, and it will show you all three options

at · May 7, 2010 at 5:02 pm

worked like a charm, thanks!

Iago Rubio · March 17, 2010 at 1:10 pm

Thanks for the tips, they are really useful.

> I know Linux guru, all those thing can e done with a single compact
> command line, but it take more time to read the man pages compared
> to run two separate and clear commands

The command is the same you use, but with a “z” at the end of the tar arguments to invoke gzip, and a “j” to invoke bz2.

tar xvfz apache-tomcat-5.5.26.tar.gz
tar xvfj apache-tomcat-5.5.26.tar.bz2

The same for compressing:

tar cvfz apache-dir.tar.gz apache-dir
tar cvfj apache-dir.tar.bz2 apache-dir

Guess you don’t need to read the man pages now ;-)

Hope this helps.

Hueoogle · February 21, 2010 at 5:36 am

DO you realize running tomcat has a listener thread and a worker thread. The listener hands off the same user as from what it accepted the connection. Lets see how long your box runs since you are letting EVERY user have ROOT ACCESS that connects to even an index.html page. Funny guys

    Stefano · February 21, 2010 at 11:10 am

    Use iptable to route port 80 on 8080 and run tomcat with a low privileges user.

Greg · February 2, 2010 at 7:59 pm

I’ve run through this, but the problem is when I try to start tomcat I get nothing:

[root@web1 tomcat]# /etc/init.d/tomcat start
Starting Tomcat service: Using CATALINA_BASE: /usr/tomcat
Using CATALINA_HOME: /usr/tomcat
Using CATALINA_TMPDIR: /usr/tomcat/temp
Using JRE_HOME: /usr/java/latest

It doesn’t report an error, but it doesn’t start either! Anyone got any ideas?

    Greg · February 3, 2010 at 12:07 am

    Ok, I’d like to make a really important note here. Don’t forget to ensure your firewall has port 8080 open if you’re leaving the Tomcat defaults as they are. Yes. I’m an idiot. Yes. That was my problem. Thank you, good night. ;-)

Syl · January 29, 2010 at 4:45 pm


About your daemon script, tomcat run behind a java startup command. Then to see status, you have to use something like:
status java | sed “s,java,tomcat,”

Malky · January 12, 2010 at 2:05 pm

Great job Stefano, Will try this tonight – are you saying that you prefer the iptable method rather than mod_proxy (I have Apache 2.2 on port 80 at the moment). I will need to configure ssl in the future for my tomcat requests and thought it might be better to use mod_proxy. Any suggestions.



    Stefano · January 12, 2010 at 2:45 pm

    I prefer iptable to avoid to manage an apache and tomcat with native librarie can be an efficient web server. Clearly under heavy load dur to static content (like images) an apache can make the difference.
    I manage a lot of virtual hosts, so having only tomcat I can configure only it. About SSL, i use the ssl connector of tomcat without problems.

roy · December 14, 2009 at 7:16 am

Some additional notes.

1. Make sure you install the right java version 32 or 64. When I tried installing a 32 version on a 64 centos, it gave a very cryptic error message. Thanks to google I was able to decipher it.

2. You need to run as root if you want to use port 80. There are workarounds though that requires modifying iptables and whatnots.

    Stefano · December 18, 2009 at 1:27 pm

    Thank you very much for the adds. Yes, I use a iptable roule to have Tomcat on the 80 even if it is configured to listen to the 8080.

krishna · November 10, 2009 at 7:53 am

This is very informative article… I really appreciate it.


Leave a Reply