Sunday, 22 May 2011

Install Tomcat

Download and extract Tomcat
wget http://apache.unixteacher.org/tomcat/tomcat-7/v7.0.12/bin/apache-tomcat-7.0.12.tar.gz
mv apache-tomcat-7.0.12.tar.gz /usr/share/apache-tomcat-7.0.12.tar.gz
cd /usr/share
tar -xzf apache-tomcat-7.0.12.tar.gz


Now you have Apache Tomcat on your server. For some unknown and stupid reason this package does not install Tomcat as a service so, while you have it, it doesn’t really work yet.

Configure Tomcat service
cd /etc/init.d
vi tomcat
(and paste the code below)
#!/bin/bash
# description: Tomcat Start Stop Restart
# processname: tomcat
# chkconfig: 234 20 80
JAVA_HOME=/usr/java/jdk1.6.0_25
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
CATALINA_HOME=/usr/share/apache-tomcat-7.0.12

case $1 in
start)
sh $CATALINA_HOME/bin/startup.sh
;;
stop)
sh $CATALINA_HOME/bin/shutdown.sh
;;
restart)
sh $CATALINA_HOME/bin/shutdown.sh
sh $CATALINA_HOME/bin/startup.sh
;;
esac
exit 0


Set permissions for your new file
chmod 755 tomcat
chown root:root tomcat

Load at startup / start
chkconfig --add tomcat
chkconfig --level 234 tomcat on
service tomcat start

Test Tomcat
It’s time to see if it works:
lynx localhost:8080

This should work now. You should also try http://12.34.56.78:8080 in your browser (after you replace that IP with yours). This might not work because of your firewall so if it doesn’t while lynx localhost:8080 works you should check your iptables configuration.

Now you have Apache Tomcat running on port 8080. If you want this to be a production server (or just want to use some goodies of Apache HTTPD like mod_rewrite) you should connect Tomcat with HTTPD with the Tomcat connector also known as mod_jk.

So, let’s have mod_jk, easier then ever!

No comments:

Post a Comment