How To Install Apache Tomcat 7 On CentOS 6


To install Apache Tomcat on CentOS, make sure you have the latest version of java installed on your system. Otherwise just download the Java RPM or BIN from the following link:
http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u25-download-346242.html

Install the httpd package using YUM
[root@server ~] # yum install httpd -y

Start the httpd service and make it available even after reboot.
[root@server ~] # service httpd start

[root@server ~] # chkconfig httpd on

Check which version of java is installed by default, on your system
[root@server ~] # java -version

Create a directory java under /usr
[root@server ~] # mkdir /usr/java

Go to the download location where you downloaded the JDK file.
[root@server ~] # cd Downloads


[root@server Downloads] # cp jdk-6u25-linux-i586-rpm.bin /usr/java

[root@server Downloads] # cd /usr/java

[root@server java] # chmod 775 jdk-6u25-linux-i586-rpm.bin

[root@server java] # ./jdk-6u25-linux-i586-rpm.bin

It will self extract and install java on your system.

Now check the java version
[root@server java] # java -version

If it still remains the same then execute the following
[root@server java] # ln -sf /usr/java/jdk1.6.0_25/bin/java   /usr/bin/java (Here s is for softlink, f is forcefully)

Now verify the java version, it should now point out to the new version.

Download the tomcat package from the apache tomcat website using the following link
http://apache.techartifact.com/mirror/tomcat/tomcat-7/v7.0.29/bin/apache-tomcat-7.0.29.tar.gz

After downloading the package copy the package to the /usr/share directory.
[root@server java] # cd /root/Downloads

[root@server Downloads] # cp apache-tomcat-7.0.29.tar.gz  /usr/share

[root@server Downloads] # cd /usr/share

[root@server share] # tar -xvzf apache-tomcat-7.0.29.tar.gz

[root@server share] # cd apache-tomcat-7.0.29

[root@server apache-tomcat-7.0.29] # cd bin


[root@server bin] # vim catalina.sh
JAVA_HOME=/usr/java/jdk1.6.0_25              (Insert this line at the start of the file)


Start the tomcat service using the script
[root@server bin] # ./startup.sh


Check for errors in the file /usr/share/apache-tomcat-7.0.29/logs/catalina.out
[root@server bin] # cat /usr/share/apache-tomcat-7.0.29/logs/catalina.out
If you dont have any errors then you can proceed further, or else rectify it first.


Making the Tomcat script.
[root@server bin] # cd /etc/init.d


[root@server init.d] # vim tomcat

#!/bin/bash
# chkconfig: 234 20 80
# description: Tomcat Server basic start/shutdown script
# processname: tomcat
JAVA_HOME=/usr/java/jdk1.6.0_25
export JAVA_HOME
TOMCAT_HOME=/usr/share/apache-tomcat-7.0.29/bin
START_TOMCAT=/usr/share/apache-tomcat-7.0.29/bin/startup.sh
STOP_TOMCAT=/usr/share/apache-tomcat-7.0.29/bin/shutdown.sh
start() {
echo -n "Starting tomcat: "
cd $TOMCAT_HOME
${START_TOMCAT}
echo "done."
}
stop() {
echo -n "Shutting down tomcat: "
cd $TOMCAT_HOME
${STOP_TOMCAT}
echo "done."
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 10
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
esac
exit 0

Change the permission on the tomcat script that we just created.
[root@server init.d] # chmod 755 tomcat


Test the script by stop and stopping the tomcat service.
[root@server init.d] # service tomcat stop

[root@server init.d] # service tomcat start

Add the tomcat to the chkconfig
[root@server init.d] # chkconfig --add tomcat

[root@server init.d] # chkconfig tomcat on

Now open a browser and test the homepage of the tomcat.
[root@server init.d] # firefox http://localhost:8080

Then you should be able to view the below screen like this

Post a Comment

Previous Post Next Post