Installing Tomcat 7 on CentOS 6

CentOS is a stable Linux distribution suited for running web application servers such as Tomcat. CentOS shares the same code base as the commercial enterprise Linux from Red Hat (RHEL) and is widely used as a server Linux distribution. In this article, I will show you how easy it is to setup a Tomcat 7 web application server on a minimal CentOS 6 installation. Please note that I use 64-bit versions for the example here.

Getting Tomcat 7 up and running on CentOS 6 involves the following steps,

  • Install CentOS 6
  • Install Oracle Java Development Kit (JDK 1.6)
  • Install Tomcat 7
  • Configure CentOS 6 firewall for opening up Tomcat port

Install CentOS 6

I recommend installing the minimal ISO from the official repository. The minimal ISO (CentOS-6.0-x86_64-minimal.iso – 290MB) contains the bare minimum set of packages required for a CentOS system to get up and running. It also contains packages such as yum using which you can later add additional packages. Installing minimal ISO keeps the number of installed packages to a minimum there by increasing the overall security of the CentOS installation.

Download the ISO file, burn it to a CD and install it on your server machine.

Install Oracle Java Development Kit (JDK 1.6)

In order to install JDK, you either need an active internet connection from CentOS installation or you need to be able copy the JDK binary to the CentOS installation. Assuming you have Ethernet connection to your server, run the following command to get an IP address from DHCP server,

dhclient eth0

Run the ifconfig command to verify that you have an active Ethernet connection and an IP address allocated from the local LAN.

Now we need to install the wget package in CentOS which lets us download files from the command line. We will later use this command to download JDK and Tomcat binaries. Use the yum tool to download and install wget utility. Yum is part of the minimal CentOS install.

yum install wget

Now use the wget tool to download 64 bit RPM binaries for Oracle JDK 6.


Now you may be wondering how I got the URL for the RPM. Visit Oracle JDK download site and then click on download link for JDK 6. Accept the license agreement on the next page and then right click and copy the URL for the Linux x64 RPM. Obviously you need to get the URL from a different machine.

Getting the download link for Oracle JDK

Now using the chmod command, change the downloaded file to an executable file,

chmod +x jdk-6u29-linux-x64-rpm.bin

Run the downloaded file to install Oracle JDK 6 on CentOS.


By default Java binaries are installed in /usr/java folder. Verify the Java installation by running the following command,

java -version


Install Tomcat 7

Installing Tomcat is similar to installing Java. Download the Tomcat 7 binary using the wget tool,


You can find the URL for Tomcat 7 binary from the Tomcat 7 download page. Download the tar.gz version.

I prefer to install Tomcat on /usr/share folder. Move the downloaded binary to /usr/share folder,

mv apache-tomcat-7.0.22.tar.gz  /usr/share/

Extract the Tomcat binaries using the following command,

tar -xzf apache-tomcat-7.0.22.tar.gz

To start Tomcat, go to the bin folder of Tomcat installation and then run the script,

cd /usr/share/apache-tomcat-7.0.22/bin


You can verify that tomcat is running by wget on the localhost. Note that by default tomcat listens on port 8080,

wget http://localhost:8080

If tomcat is running, wget will download the default page as index.html in the current folder.

You can access Tomcat from another machine by replacing the localhost by the actual IP address of your CentOS server. However initially I was unable to access Tomcat from another machine since by default CentOS firewall blocks port 8080.

Configure CentOS 6 firewall for opening up Tomcat port

Even the minimal install of CentOS has the firewall up and running. By default the firewall restricts access to various ports and that includes the default tomcat port 8080.

To open port 8080, we need to permanently change the iptables on CentOS. Edit the /etc/sysconfig/iptables file and add the following line to the top of the file,

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

You need to add this at the top of the file since iptables are processed from bottom to top. If you add the entry at the bottom, it may get overridden by an entry above.

For editing files, I use the vi tool which is available as part of CentOS minimal install. You can also install other editors such nano using the yum installer.

After making changes to the iptables file, restart the iptables service,

service iptables restart

The modified iptables file in my system,

Modified iptables for Tomcat on CentOS 6

Now you should be able to access the Tomcat 7 default page from another machine. If you still have problems double check that Tomcat 7 process is running,

ps -ef | grep tomcat

You should see a result containing tomcat as shown below,

Verifying whether Tomcat is running

Still having problems? Post them below!

Click here to receive Distro Tips updates in your email. Confirm your subscription by clicking on the link sent to you by feedburner!


2 Responses to “Installing Tomcat 7 on CentOS 6”
  1. Rookee says:

    It is important to add the iptables config into the top:

    :OUTPUT ACCEPT [0:0]
    -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT

    This don’t work:

    -A FORWARD -j REJECT –reject-with icmp6-adm-prohibited
    -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT

  2. Grontok Fahl says:

    Thank you for this information. It is accurate and succinct.

Speak Your Mind