X
    Categories: Tutorials

Installing Tomcat 8 on a CentOS 7 Linux VPS

In the following article we will guide you through the steps on how to install the latest Tomcat 8 on a CentOS 7 Linux VPS.

What is Tomcat?

Apache Tomcat (previously known as Jakarta Tomcat) is an application server developed by the Apache Software Foundation that executes Java servlets and renders Web pages that include Java Server Page coding.

System Requirements?

 

UPDATE SYSTEM

First thing to do is to SSH to your CentOS 7 VPS, fire up a screen session and update your system using yum:

## screen -U -S tomcat8-centos7
## yum update

You may also want to install a text editor like nano or vim

## yum install vim nano

 

SETUP JAVA

Tomcat 8 requires JAVA 7+ in order to run. We are going to install the latest version of Oracle’s JAVA JDK 8. At the time of writing this article, the latest version of JAVA is 8u25 and can be downloaded and installed using the commands below:

DOWNLOAD JAVA

for 32-bit (x86) systems:

## wget --no-cookies \
--no-check-certificate \
--header "Cookie: oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/8u25-b17/jdk-8u25-linux-i586.rpm" \
-O /opt/jdk-8-linux-i586.rpm

for 64-bit (x86_64) systems:

## wget --no-cookies \
--no-check-certificate \
--header "Cookie: oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/8u25-b17/jdk-8u25-linux-x64.rpm" \
-O /opt/jdk-8-linux-x64.rpm

INSTALL JAVA

for 32-bit (x86) systems:

## yum install /opt/jdk-8-linux-i586.rpm

for 64-bit (x86_64) systems:

## yum install /opt/jdk-8-linux-x64.rpm

CONFIGURE JAVA

configure the JAVA package using the alternatives command:

## JDK_DIRS=($(ls -d /usr/java/jdk*))
## JDK_VER=${JDK_DIRS[@]:(-1)}

## alternatives --install /usr/bin/java java /usr/java/"${JDK_VER##*/}"/jre/bin/java 20000
## alternatives --install /usr/bin/jar jar /usr/java/"${JDK_VER##*/}"/bin/jar 20000
## alternatives --install /usr/bin/javac javac /usr/java/"${JDK_VER##*/}"/bin/javac 20000
## alternatives --install /usr/bin/javaws javaws /usr/java/"${JDK_VER##*/}"/jre/bin/javaws 20000
## alternatives --set java /usr/java/"${JDK_VER##*/}"/jre/bin/java
## alternatives --set javaws /usr/java/"${JDK_VER##*/}"/jre/bin/javaws
## alternatives --set javac /usr/java/"${JDK_VER##*/}"/bin/javac
## alternatives --set jar /usr/java/"${JDK_VER##*/}"/bin/jar

VERIFY JAVA

You may want to check if JAVA has been properly setup on your CentOS Linux VPS using:

## java -version

 

SETUP TOMCAT

TOMCAT USER

Before proceeding with the Tomcat installation, let’s first create a separate system user which will run the Tomcat server:

## useradd -r tomcat8 --shell /bin/false

DOWNLOAD TOMCAT

Next, download the latest version of Tomcat 8 available at http://tomcat.apache.org/download-80.cgi . You can use wget to download it in /tmp, for example:

## wget http://mirror.tcpdiag.net/apache/tomcat/tomcat-8/v8.0.15/bin/apache-tomcat-8.0.15.tar.gz -P /tmp

INSTALL TOMCAT

Extract the contents of the Tomcat archive you just downloaded to /opt, create a symbolic link of tomcat directory to /opt/tomcat-latest and setup proper ownership using the following commands:

## tar -zxf /tmp/apache-tomcat-*.tar.gz -C /opt
## ln -s /opt/apache-tomcat-8.0.15 /opt/tomcat-latest
## chown -hR tomcat8: /opt/tomcat-latest /opt/apache-tomcat-*

START TOMCAT

Create the following systemd unit file in /etc/systemd/system/tomcat8.service

[Unit]
Description=Tomcat8
After=network.target

[Service]
Type=forking
User=tomcat8
Group=tomcat8

Environment=CATALINA_PID=/opt/tomcat-latest/tomcat8.pid
Environment=TOMCAT_JAVA_HOME=/usr/java/default
Environment=CATALINA_HOME=/opt/tomcat-latest
Environment=CATALINA_BASE=/opt/tomcat-latest
Environment=CATALINA_OPTS=
Environment="JAVA_OPTS=-Dfile.encoding=UTF-8 -Dnet.sf.ehcache.skipUpdateCheck=true -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+UseParNewGC -XX:MaxPermSize=128m -Xms512m -Xmx512m"

ExecStart=/opt/tomcat-latest/bin/startup.sh
ExecStop=/bin/kill -15 $MAINPID

[Install]
WantedBy=multi-user.target

With the unit file in place, run the following commands to start the Tomcat servce:

## systemctl daemon-reload
## systemctl restart tomcat8
## systemctl enable tomcat8

ACCESS TOMCAT

Access your newly installed Tomcat at http://YOUR_IP:8080


Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to install Tomcat 8 for you. They are available 24×7 and will take care of your request immediately. PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

View Comments

  • Same issue. Output: Job for tomcat8.service failed. See 'systemctl status tomcat8.service' and 'journalctl -xn' for details. [x@x]$ systemctl status tomcat8.service tomcat8.service - Tomcat8 Loaded: loaded (/etc/systemd/system/tomcat8.service; disabled) Active: failed (Result: exit-code) since Fri 2015-07-03 07:54:40 UTC; 11s ago Process: 12504 ExecStart=/opt/tomcat-latest/bin/startup.sh (code=exited, status=203/EXEC)

    • You should run 'journalctl -xn' for more details about why Tomcat failed to start. Thanks.

      • You should run 'journalctl -xn' for more details about why Tomcat failed to start. Thanks.

        • Our tutorial is fully tested and it is working as it should. Please follow the tutorial instructions closely.

          • Our tutorial is fully tested and it is working as it should. Please follow the tutorial instructions closely.

  • Hi sir, I tried to use : ## systemctl restart tomcat8 but I get a error : Job for tomcat8.service failed. See 'systemctl status tomcat8.service' and 'journalctl -xn' for details. Please help me to solve it. Thanks so much !