| More

Tomcat,known as Apache Tomcat or Jakarta Tomcat is a servlet container developed by ASF or Apache Software Foundation. It implements the JavaServer Pages (JSP) and Java Servlet specifications from Sun Microsystems. To make it simple, it is use as a java http web server environment where you can run your Java code.

This is a brief tutorial on installing and running tomcat in Linux.

Java SDK should be installed.

Tested in CentOS 5.X

1. Download Java SDK from sun.com website


In this tutorial, we will be using Java EE 5 SDK

2. Install Java SDK, any location is ok.

[root@flt ~]# cd /home/darwin
[root@flt darwin]# chmod +x java_ee_sdk-5_01-linux.bin
[root@flt darwin]# ./java_ee_sdk-5_01-linux.bin

You will see something like this

[root@flt darwin]# ./java_ee_sdk-5_01-linux.bin
Checking available disk space…
Checking Java(TM) 2 Runtime Environment…
Extracting Java(TM) 2 Runtime Environment files…
Extracting installation files…
Launching Java(TM) 2 Runtime Environment…

You are running the installation program for Java Platform, Enterprise Edition
5 SDK. This program asks you to supply configuration preference settings that
it uses to install the server.

Just follow the steps, type yes to agree, “<” to go back, “!” to exits
* set Java Environment Variables

Installation Directory [/opt/SDK] {“<” goes back, “!” exits}: /home/darwin
Supply the admin user’s password and override any of the other initial
configuration settings as necessary.
Admin User [admin] {“<” goes back, “!” exits}:
Admin User’s Password (8 chars minimum):
Re-enter Password:
Do you want to store admin user name and password in .asadminpass file in
user’s home directory [yes] {“<” goes back, “!” exits}?
Admin Port [4848] {“<” goes back, “!” exits}:
HTTP Port [8080] {“<” goes back, “!” exits}:
HTTPS Port [8181] {“<” goes back, “!” exits}:

The following items for the product Java Platform, Enterprise Edition 5 SDK
will be installed:

Product: Java Platform, Enterprise Edition 5 SDK
Location: /home/darwin
Space Required: 215.65 MB
Java 2 SDK, Standard Edition 5.0
Sun Java System Message Queue 4.0
Sun Java System Application Server Platform Edition 9 Update 1
Sample Applications
Java BluePrints
First Cup of Java Tutorial
Open ESB Starter Kit with JBI and BPEL

Ready to Install

1. Install Now
2. Start Over
3. Exit Installation

What would you like to do [1] {“<” goes back, “!” exits}? 1

Installing Java Platform, Enterprise Edition 5 SDK
|-1%————–25%—————–50%–Dec 9, 2009 6:52:55 AM com.sun.jbi.installer.OpenEsbInstaller main
INFO: OpenESB Starter Kit successfully installed in /home/darwin/addons/jbi

Installation Successful.

3.Set the Java Environment variables

[root@flt ~]# export JAVA_HOME=/home/darwin/jdk
[root@flt ~]# echo $PATH
[root@flt ~]# export PATH=$PATH:${JAVA_HOME}/bin
[root@flt ~]# echo $PATH

4. Test Java by displaying the version

[root@flt ~]# java -version

java version “1.5.0_09”
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_09-b03)
Java HotSpot(TM) Client VM (build 1.5.0_09-b03, mixed mode)

5. Download Tomcat from tomcat.apache.org website

if you want to download apache tomcat ver.5.5.x, get it from http://tomcat.apache.org/download-55.cgi

For this tutorial, we will be downloading and installing version 6.0, get it from http://tomcat.apache.org/download-60.cgi

#cd /usr/local/src
# wget http://www.ip97.com/apache.org/tomcat/tomcat-6/v6.0.20/bin/apache-tomcat-6.0.20.tar.gz

6.Extract the binary tarball file

[root@flt src]# tar zxvf apache-tomcat-6.0.20.tar.gz

7. Install Tomcat

[root@flt src]# cd apache-tomcat-6.0.20
[root@flt apache-tomcat-6.0.20]# cd bin
[root@flt bin]# tar zxvf jsvc.tar.gz
[root@flt bin]# cd jsvc-src/
[root@flt jsvc-src]# chmod +x configure
[root@flt jsvc-src]# ./configure
[root@flt jsvc-src]#make
[root@flt jsvc-src]#cp jsvc ..
[root@flt jsvc-src]#cd ..

8. Run tomcat

[root@flt bin]# ./startup.sh

It will show something like:
Using CATALINA_BASE: /usr/local/src/apache-tomcat-6.0.20
Using CATALINA_HOME: /usr/local/src/apache-tomcat-6.0.20
Using CATALINA_TMPDIR: /usr/local/src/apache-tomcat-6.0.20/temp
Using JRE_HOME: /home/darwin/jdk

9. Using your favorite browser, type http://serverip:8080

You should see the Apache tomcat default homepage, meaning tomcat was successfully installed

Notes: If you did not see the default tomcat page, you can try this following troubleshooting steps
a. Check if tomcat is running using ps

[root@flt bin]# ps -ef |grep tomcat

It will show something like:
root 5872 1 1 07:24 pts/2 00:00:03 /home/darwin/jdk/bin/java
-Djava.endorsed.dirs=/usr/local/src/apache-tomcat-6.0.20/endorsed -classpath
:/usr/local/src/apache-tomcat-6.0.20/bin/bootstrap.jar -Dcatalina.base=/usr/local/src/apache-tomcat-6.0.20
-Dcatalina.home=/usr/local/src/apache-tomcat-6.0.20 -Djava.io.tmpdir=/usr/local/src/apache-tomcat-6.0.20/temp org.apache.catalina.startup.Bootstrap start

b.check if tcp port 8080 is open or on “LISTEN” status

[root@flt bin]# netstat -an |grep 8080

It will show something like:
tcp 0 0 :::8080 :::* LISTEN

* you can also use nmap port scanner to verify

[root@flt bin]# nmap localhost

If port is open, you can see something like:
8080/tcp open http-proxy

c. check if the tcp port 8080 is allowed in your iptables, if you don’t have a customized script, you can add it on your “setup” firewall configuration or in your /etc/sysconfig iptables, add this

-A RH-Firewall-1-INPUT -p tcp -m state –state NEW -m tcp –dport 8080 -j ACCEPT

10. Test tomcat if it can display html

a. Go to webapps/ROOT in the tomcat directory and create a test page titled test.html and write in it

This is a tomcat test html page!

b. Open the URL http://serverip:8080/test.html you should see your page

11. Test tomcat if it can display java server pages (jsp)

a. Go to webapps/ROOT in the tomcat directory and create page test.jsp and write in it:

<title>Hello World</title>
String message = “Hello World!Tomcat is running.”;
<hr color=”#000000″ />
<h2><font color=”#3366cc”><%= message%></font></h2>
<h3><font color=”#0000ff”><%= new java.util.Date() %> </font></h3>
<hr color=”#000000″ />
b.save and open in your browser, http://serveriplocalhost:8080/test.jsp

you should see the “Hello World!Tomcat is running” and below that is the current date

11. Shutting down tomcat process
a. Go to tomcat bin directory

[root@flt bin]# ./shutdown.sh

It will display something like:
Using CATALINA_BASE: /usr/local/src/apache-tomcat-6.0.20
Using CATALINA_HOME: /usr/local/src/apache-tomcat-6.0.20
Using CATALINA_TMPDIR: /usr/local/src/apache-tomcat-6.0.20/temp
Using JRE_HOME: /home/darwin/jdk

Quick Tip: Installing as a service and auto-boot in start up

A.  Create tomcat file under /etc/init.d directory and put the script below

[root@flt bin]# cd /etc/init.d/
[root@flt init.d]# vi tomcat

here’s the script:


# 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

export JAVA_HOME=/home/dar/jdk


echo -n $”Starting Tomcat service: ”
#daemon -c

action $”Stopping Tomcat service: ” $shutdown


# See how we were called.
case “$1″ in
# This doesn’t work 😉
status tomcat
echo $”Usage: $0 {start|stop|status|restart}”
exit 1

exit 0


B. Replace the variables based on your setup:

export JAVA_HOME=/home/dar/jdk

C. Make tomcat file executable

[root@flt init.d]# chmod 755 tomcat

D.  Try to start and stop tomcat by issuing the command

[root@flt init.d]# service tomcat start
[root@flt init.d]# service tomcat stop

E.  Type “setup” to check under System services if “tomcat” already selected to boot during start-up,if not you can issue this command

[root@flt init.d]# chkconfig –add tomcat


Leave a comment

Name: (Required)

E-mail: (Required)




About FLT

This site is dedicated to everyone who likes to learn and explore the beautiful world of Linux. If you have comments and suggestions, please feel free to email at freelinuxtutorials@gmail.com. I am happy to serve and share things esp. that is free and enjoyable as Linux.