Copy file to /usr/local.
# cd /usr/local/ # gzip -d jakarta-tomcat-4.1.31.tar.gz # tar xvf jakarta-tomcat-4.1.31.tar.gzSet the
CATALINA_HOME="/usr/local/jakarta-tomcat-4.1.31" export CATALINA_HOMESet the
JAVA_HOME environment variable. I set this in /etc/profile:
JAVA_HOME="/usr/java/j2sdk1.4.1_03" export JAVA_HOME
You may want to set up a symbolic link to /usr/local/jakarta-tomcat...
ln -s jakarta-tomcat-4.1.31/ jakarta-tomcatIf you do, then you can refer to
/usr/local/jakarta-tomcat instead. You can then update your /etc/profile CATALINA_HOME variable to use the symlink instead. This will also make it easier to deal with Tomcat upgrades.
# cd /usr/local/jakarta-tomcat-4.1.31/bin # ./startup.sh
# cd /usr/local/jakarta-tomcat-4.1.31/bin # ./shutdown.sh
localhost:8080
and you should see the default Tomcat page. This page includes JSP and Servlet examples for you to try.
server.xml file located at $TOMCAT_HOME/conf/server.xml.
We need to add a new Context configuration. I'm going to add a Context named "sparling":
<Context path="/sparling"
docBase="webapps/sparling"
crossContext="false"
reloadable="true">
</Context>
Refer to the User's Guide for an explantation of these lines.
Now we need to create the sparling directory to $TOMCAT_HOME/webapps.
# cd $CATALINA_HOME # cd webapps # mkdir sparling # cd sparling # mkdir WEB-INF # cd WEB-INF # mkdir classesNow restart Tomcat. This will rebuild the tomcat-apache.conf file.
Now move your servlet class file to the $CATALINA_HOME/webapps/sparling/WEB-INF/classes directory. For example, if we add the file HelloWorld.class to this directory, then we can access the servlet via the browser at: http://localhost:8080/sparling/servlet/HelloWorld.
Create tomcat user # groupadd tomcat # useradd -g tomcat tomcat # chown -R tomcat:tomcat /usr/local/jakarta-tomcat-4.1.31 # chown tomcat:tomcat /usr/local/jakarta-tomcat Create /etc/rc.d/init.d/tomcat # vi /etc/rc.d/init.d/tomcat
#!/bin/sh
#
# Startup script for Tomcat
JAVA_HOME=/usr/java/j2sdk1.4.1_03
export JAVA_HOME
start_tomcat=/usr/local/jakarta-tomcat-4.1.31/bin/startup.sh
stop_tomcat=/usr/local/jakarta-tomcat-4.1.31/bin/shutdown.sh
start() {
echo -n "Starting tomcat: "
su -c ${start_tomcat} - tomcat
echo "done."
}
stop() {
#echo -n "Shutting down http: "
echo -n "Shutting down tomcat: "
${stop_tomcat}
echo "done."
}
# See how we were called
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 10
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
esac
exit 0
export CLASSPATH=$CLASSPATH:$CATALINA_HOME/common/lib/servlet.jar