Saminnet-Search Article Wiki Forum Piwigo SNS Cloud vtiger Sugar
Tomcat 8 CenOS 7

Tomcat 8 CenOS 7


Apache Tomcat is a web server and servlet container that is used to serve Java applications. Tomcat is an open source implementation of the Java Servlet and JavaServer Pages technologies, released by the Apache Software Foundation. This tutorial covers the basic installation and some configuration of the latest release of Tomcat 8 on your CentOS 7 server.


Before you begin with this guide, you should have a separate, non-root user account set up on your server. You can learn how to do this by completing steps 1-3 in theツinitial server setupツfor CentOS 7. We will be using theツdemoツuser created here for the rest of this tutorial.

Install Java

Tomcat requires that Java is installed on the server, so any Java web application code can be executed. Let's satisfy that requirement by installing OpenJDK 7 with yum.

To install OpenJDK 7 JDK using yum, run this command:

  • sudo yum install java-1.7.0-openjdk-devel

Answerツyツat the prompt to continue installing OpenJDK 7.

Note that a shortcut to the JAVA_HOME directory, which we will need to configure Tomcat later, can be found atツ/usr/lib/jvm/jre.

Now that Java is installed, let's create aツtomcatツuser, which will be used to run the Tomcat service.

Create Tomcat User

For security purposes, Tomcat should be run as an unprivileged user (i.e. not root). We will create a new user and group that will run the Tomcat service.

First, create a newツtomcatツgroup:

  • sudo groupadd tomcat

Then create a newツtomcatツuser. We'll make this user a member of theツtomcatツgroup, with a home directory ofツ/opt/tomcatツ(where we will install Tomcat), and with a shell ofツ/bin/falseツ(so nobody can log into the account):

  • sudo useradd -M -s /bin/nologin -g tomcat -d /opt/tomcat tomcat

Now that ourツtomcatツuser is set up, let's download and install Tomcat.

Install Tomcat

The easiest way to install Tomcat 8 at this time is to download the latest binary release then configure it manually.

Download Tomcat Binary

Find the latest version of Tomcat 8 at theツTomcat 8 Downloads page. At the time of writing, the latest version isツ8.0.23. Under theツBinary Distributionsツsection, then under theツCoreツlist, copy the link to the "tar.gz".

Let's download the latest binary distribution to our home directory.

First, change to your home directory:

  • cd ~

Then useツwgetツand paste in the link to download the Tomcat 8 archive, like this (your mirror link will probably differ from the example):

  • wget

We're going to install Tomcat to theツ/opt/tomcatツdirectory. Create the directory, then extract the the archive to it with these commands:

  • sudo mkdir /opt/tomcat
  • sudo tar xvf apache-tomcat-8*tar.gz -C /opt/tomcat --strip-components=1

Now we're ready to set up the proper user permissions.

Update Permissions

Theツtomcatツuser that we set up needs to have the proper access to the Tomcat installation. We'll set that up now.

Change to the Tomcat installation path:

  • cd /opt/tomcat

Then give theツtomcatツuserツwriteツaccess to theツconfツdirectory, andツreadツaccess to the files in that directory:

  • sudo chgrp -R tomcat conf
  • sudo chmod g+rwx conf
  • sudo chmod g+r conf/*

Then make theツtomcatツuser the owner of theツwebapps,ツwork,ツtemp, andツlogsツdirectories:

  • sudo chown -R tomcat webapps/ work/ temp/ logs/

Now that the proper permissions are set up, let's set up a Systemd unit file.

Install Systemd Unit File

Because we want to be able to run Tomcat as a service, we will set up a Tomcat Systemd unit file .

Create and open the unit file by running this command:

  • sudo vi /etc/systemd/system/tomcat.service

Paste in the following script. You may also want to modify the memory allocation settings that are specified inツCATALINA_OPTS:

# Systemd unit file for tomcat
Description=Apache Tomcat Web Application Container


Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'

ExecStop=/bin/kill -15 $MAINPID



Save and exit. This script tells the server to run the Tomcat service as theツtomcatツuser, with the settings specified.

Now reload Systemd to load the Tomcat unit file:

  • sudo systemctl daemon-reload

Now you can start the Tomcat service with thisツsystemctlツcommand:

  • sudo systemctl start tomcat

If you want to enable the Tomcat service, so it starts on server boot, run this command:

  • sudo systemctl enable tomcat

Tomcat is not completely set up yet, but you can access the default splash page by going to your domain or IP address followed byツ:8080ツin a web browser:

Open in web browser:

You will see the default Tomcat splash page, in addition to other information. Now we will go deeper into the installation of Tomcat.

Configure Tomcat Web Management Interface

In order to use the manager webapp that comes with Tomcat, we must add a login to our Tomcat server. We will do this by editing theツtomcat-users.xmlツfile:

  • sudo vi /opt/tomcat/conf/tomcat-users.xml

This file is filled with comments which describe how to configure the file. You may want to delete all the comments between the following two lines, or you may leave them if you want to reference the examples:

tomcat-users.xml excerpt

You will want to add a user who can access theツmanager-guiツandツadmin-guiツ(webapps that come with Tomcat). You can do so by defining a user similar to the example below. Be sure to change the username and password to something secure:

tomcat-users.xml 窶 Admin User
    <user username="admin" password="password" roles="manager-gui,admin-gui"/>

Save and quit the tomcat-users.xml file. To put our changes into effect, restart the Tomcat service:

  • sudo systemctl restart tomcat

Access the Web Interface

Now that Tomcat is up and running, let's access the web management interface in a web browser. You can do this by accessing the public IP address of the server, on port 8080:

Open in web browser:

You will see something like the following image:

Tomcat root

As you can see, there are links to the admin webapps that we configured an admin user for.

Let's take a look at the Manager App, accessible via the link orhttp://server_IP_address:8080/manager/html:

Tomcat Web Application Manager

The Web Application Manager is used to manage your Java applications. You can Start, Stop, Reload, Deploy, and Undeploy here. You can also run some diagnostics on your apps (i.e. find memory leaks). Lastly, information about your server is available at the very bottom of this page.

Now let's take a look at the Host Manager, accessible via the link orツhttp://server_IP_address:8080/host-manager/html/:

Tomcat Virtual Host Manager

From the Virtual Host Manager page, you can add virtual hosts to serve your applications from.


Your installation of Tomcat is complete! Your are now free to deploy your own Java web applications!


0 #1 Guest 2019-02-21 02:11
Nicce piece! I have picked up many ideas, thanks for sharting with us.
When is your next article released?

Also isit my web site ... free help desk software web-based
learning e-learning (Chastity)

Category Database

TweetTweet Share on LinkedInShare on LinkedIn Share on Google+Google+ Submit to RedditReddit Publish on WordPress WordPress Send emailSend email