How to Install Apache Tomcat 8.0.x on Linux

February 3, 2015 | By
| 3 Replies More

Hi everyone, today we'll be learning how to install Tomcat 8.0.18 on Linux machine. This tutorial includes short description of Apache Tomcat and some significant features of Tomcat 8.

Apache Tomcat is an open source web server and servlet container developed by the Apache Software Foundation. It implements the Java Servlet, JavaServer Pages (JSP), Java Unified Expression Language and Java WebSocket specifications from Sun Microsystems and provides a web server environment for Java code to run in.

Tomcat 8.0.18 is the latest version of the 8th generation, it’s aligned with Java EE 7. In addition to supporting updated versions of the Java EE specifications, Tomcat 8 includes a number of improvements compared to Tomcat 7 , here are some few details about Tomcat 8.

    • Tomcat 8 requires JAVA 7 to work.
    • Tomcat 8 supports Java Servlet 3.1
    • Tomcat 8 supports JavaServer Pages 2.3
    • Tomcat 8 supports Java Unified Expression Language 3.0
    • Tomcat 8 supports Java WebSocket 1.0

So, here are the steps that we'll need to follow to setup and configure Apache Tomcat 8.0.18 on our Linux Machine which includes RHEL/CentOS, Ubuntu and their derivatives.

1. Installing and Configuring Java

First of all, we'll need to make sure that we have properly installed JAVA in our Linux machine before heading up to install Tomcat. We'll need 7 or greater version of JAVA installed in our Linux machine. To check if we have a working JAVA installed in our system, we'll need to run the following command in a shell or a terminal.

# java -version

We have JAVA installed in our system already. But incase if have no JAVA installed in the machine, we'll need to install it. It can be installed by executing the following command in a shell or terminal. Installing JAVA depends upon the distribution of Linux Operating System used currently.

To install on Ubuntu Distribution:

# apt-get install openjdk-7-jdk

To install on CentOS/RHEL 7 Distribution:

# yum install java-1.7.0-openjdk

 To install on OpenSuse Distribution:

# zypper install java-1_7_0-openjdk

 2. Downloading Tomcat 8

We can download tomcat from the official download site of tomcat. As the latest and stable release of tomcat now is version 8.0.18, we'll gonna download tomcat 8.0.18 and install it on our Linux system. So, we'll gonna download its tarball file ie tar.gz inside /tmp folder and then extract it under /usr/share/ . To do so, we'll need to execute the following commands in a shell or terminal.

# cd /tmp/
# wget http://apache.mirrors.hoobly.com/tomcat/tomcat-8/v8.0.18/bin/apache-tomcat-8.0.18.tar.gz

Downloading Tomcat

Now, we'll gonna extract the files of the tarballs to /usr/share/

# cd /usr/share/
# tar -zxvf /tmp/apache-tomcat-8.0.18.tar.gz

Extracting Tomcat

3. Adding tomcat user & group

It is highly recommended not to run Tomcat as root. So, we will need to create an unprivileged user for it and set the appropriate owner of the tomcat folder:

# groupadd tomcat
# useradd -g tomcat -s /bin/bash -d /usr/share/apache-tomcat-8.0.18 tomcat

 

adding user tomcat

# chown -Rf tomcat.tomcat /usr/share/apache-tomcat-8.0.18/

chown tomcat

4. Running Tomcat 8

Now, finally we'll start our apache tomcat server. First we'll need to switch to the unprivileged user with the command below.

# su – tomcat

Then, we'll start our Apache Tomcat a shell script called startup.sh which is inside bin folder. So, we'll need to run:

$ cd ~/bin
$ ./startup.sh

starting Tomcat

And yes, we have successfully started tomcat 8.0.18 . Now if everything went according, we must be able to access it in our browser with http://localhost:8080 or http://SERVER-IP:8080 according to the host.

If you are trying to run tomcat 8 on firewall enabled CentOS 7 then we may need to open port 8080 which can be done by running the below commands under root access:

# firewall-cmd --zone=dmz --add-port=2888/tcp --permanent
# firewall-cmd --reload

To shutdown it, we can simply run another shell script called shutdown.sh which will automatically shutdown tomcat server.

$ ./shutdown.sh

5. Setup user accounts

Finally we have to configure Tomcat users so they can access admin/manager sections. We can do that by adding the users in the ~/conf/tomcat-users.xml file with our favorite text editor.

$ nano ~/conf/tomcat-users.xml

Now, we'll wanna add a manager-gui role to a user with username as linoxide and password as linoxidepass:

<role rolename="manager-gui"/>
<user username="linoxide" password="linoxidepass" roles="manager-gui"/>

Then, we'll wanna add an admin-gui role to an user with username as admin and password as adminpass:

<role rolename="admin-gui"/>
<user username="admin" password="adminpass" roles="manager-gui, admin-gui"/>

Adding Tomcat Users

Note: Please change the username and password according to your desire.

After setting up the admin and managers roles, we'll need restart the Tomcat and then try to access the admin section. To do so, we'll need to run the below commands in a shell or terminal:

$ cd ~/bin
$ ./shutdown.sh
$ ./startup.sh

Restarting Tomcat

To login to the manager app, we'll need to browse to http://ip-address:8080/manager/ or http://localhost:8080/manager according to the host configuration. And if everything went cool, we must get a login window as in which we must enter the username and password which we just added above.

Tomcat Manager Login

After login, we'll see the below as we have successfully logged in:

Tomcat Manager App

6. Running Multiple Instances (Optional)

Sometimes we'll need to run more than one instance of Tomcat on the same server. To do this, we'll need to run as root  then we'll need to go back to the /usr/share directory where we first downloaded tomcat and extract it again in a different folder like this:

Note: To exit user tomcat to root, please execute exit in the current shell or terminal.

# cd /usr/share
# mkdir apache-tomcat-2

Creating Another Instance

# tar -zxvf /tmp/apache-tomcat-8.0.18.tar.gz -C apache-tomcat-2 --strip-components 1
# chown -Rf tomcat.tomcat /usr/share/apache-tomcat-2/

Extracting tomcat 8 for another instance

Now we need switch user to tomcat to open the conf/server.xml file in the new installation folder and change the port numbers like below.  First, to switch user to tomcat from root, execute the following:

# su - tomcat

Now, shutdown the server by running the below command:

$ ~/bin/shutdown.sh

Then, to edit the file server.xml, we'll need to open it with a text editor as:

$ nano ~/conf/server.xml

The shutdown port from:

<Server port="8005" shutdown="SHUTDOWN">

To

<Server port="8006" shutdown="SHUTDOWN">

Configuring Shutdown Port

The connector port from:

<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

To

<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

Configuring Connector Port

And the AJP port from:

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

To

<Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />

Configuring AJP port

Now, we'll want to save the changes we made to that file. After that, we can just switch back to the tomcat user and start the second instance like this:

$ cd ~/bin
$ ./startup.sh

Starting Tomcat Instance

If everything went accordingly, we should now access the new instance of tomcat with your browser at http://localhost:8081/ or http://SERVER-IP:8081/

New Tomcat Instance

Conclusion

Hurray! We have successfully installed Tomcat version 8.0.18 in our Linux based Distribution. This tutorial includes installation of Tomcat 8.0.18 in different distributions like Red Hat, CentOS, Ubuntu, OpenSuse and their derivatives. Tomcat 8.0.18 is the latest version of the 8th generation, it’s aligned with Java EE 7. If you have any questions, comments, feedback please do write on the comment box below and let us know what stuffs needs to be added or improved. Thank You! Enjoy your latest Tomcat 8.0.18 :-)

Filed Under : LINUX HOWTO, WEB SERVERS

Free Linux Ebook to Download

Comments (3)

Trackback URL | Comments RSS Feed

  1. Mike says:

    Thank you so much for the article. I managed to get Tomcat up and running on my Ubuntu VPS thanks to your tutorial. Really appreciated.

    I also used a section from https://vpsineu.com/blog/how-to-set-up-tomcat-8-with-nginx-reverse-proxy-on-an-ubuntu-14-04-vps/ to create reverse proxy so that I can use my domain name for my tomcat application.

  2. tom cat says:

    i don't think you gave the tomcat scripts execution rights.

Leave a Reply

Commenting Policy:
Promotion of your products ? Comment gets deleted.
All comments are subject to moderation.