How to install Apache Tomcat on CentOS

Apache Tomcat is one of the most popular and powerful web application servers on Linux. You can use Tomcat to host Java servlets or JSP web applications. As with any other Apache-licensed software, Tomcat is available free of charge under liberal Apache license. If you would like to install Apache Tomcat on CentOS, here is a guide for you. For Tomcat installation on Debian or Ubuntu. refer to this guide instead.

First, you need to install Java Development Kit (JDK). To do that, set up Repoforge repository on your CentOS system, and then run the following.

$ sudo yum install java-1.6.0-openjdk-devel -y

Then, set up JAVA_HOME environment variable.

$ sudo sh -c 'echo export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk > /etc/profile.d/java.sh'
$ source /etc/profile.d/java.sh

Now download Apache Tomcat, and install it. Since Apache Tomcat is distributed as binaries, all you have to do is to copy it somewhere in your CentOS.

$ wget http://apache.mirrors.tds.net/tomcat/tomcat-7/v7.0.35/bin/apache-tomcat-7.0.35.tar.gz
$ sudo tar xvzf apache-tomcat-7.0.35.tar.gz -C /opt
$ sudo chmod +r /opt/apache-tomcat-7.0.35/conf/*

Then set up a necessary environment variable as follows.

$ sudo sh -c 'echo export CATALINA_HOME=/opt/apache-tomcat-7.0.35 > /etc/profile.d/tomcat.sh'
$ source /etc/profile.d/tomcat.sh

Finally, activate Tomcat by running the following startup script.

$ sudo $CATALINA_HOME/bin/startup.sh

Go to http://your_centos_ip:8080 in your browser to test if Apache Tomcat is running okay. If it is, you will see the following in your browser window.

If you cannot access the above Tomcat page, make sure to stop iptables, since CentOS has iptables on by default, and it is set to block the Tomcat's default listening port 8080.

$ sudo service iptables stop
$ sudo chkconfig iptables off

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of Xmodulo.com. He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.
Your name can also be listed here. Write for us as a freelancer.

5 thoughts on “How to install Apache Tomcat on CentOS

  1. I follow your instructions but Solr give a 404 error.
    In Tomcat admin I get this error: FAIL - Application at context path /solr-example could not be started when I try to START the application from the applications manager.

    I believe it has to do with permissions. Maybe the data directory doesn't allow Tomcat to write in it?

  2. Thanks, worked without a problem (except the download link was dead). My bash_history on a fresh CentOS 6 box (executed as root):

    yum install java-1.7.0-openjdk
    yum install java-1.7.0-openjdk-devel
    java -version
    javac -version
    echo export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk.x86_64 > /etc/profile.d/java.sh
    source /etc/profile.d/java.sh
    wget http://apache.mirrors.tds.net/tomcat/tomcat-7/v7.0.35/bin/apache-tomcat-7.0.35.tar.gz
    tar xvzf apache-tomcat-7.0.42.tar.gz -C /opt
    chmod +r /opt/apache-tomcat-7.0.42/conf/*
    echo export CATALINA_HOME=/opt/apache-tomcat-7.0.42 > /etc/profile.d/tomcat.sh
    source /etc/profile.d/tomcat.sh
    $CATALINA_HOME/bin/startup.sh

Leave a comment

Your email address will not be published. Required fields are marked *