How To Install Apache Tomcat 8 On Ubuntu 16
How To Install Apache Tomcat 8 On Ubuntu 16
How To Install Apache Tomcat 8 On Ubuntu 16
Posted April 27, 2016 346.2k JAVA APPLICATION UBUNTU UBUNTU 16.04
Introduction
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 ervlet and
Javaerver Pages technologies, released b the Apache oftware Foundation. This
tutorial covers the basic installation and some configuration of the latest release of
Tomcat 8 on our Ubuntu 16.04 server.
Prerequisites
Before ign
ouup for our newsletter.
begin with thisGet the latest
guide, oututorials
shouldonhave
sAdmin and open
a non-root source
user topics.
with sudo ×
C R O L Lour
TO TO P
privileges set up on our server. You can learn how to do this b completing
Enter our email address ign Up
1 de 25 9/11/17 09:16
How To Install Apache Tomcat 8 on Ubuntu 16.0... https://www.digitalocean.com/community/tutoria...
Now that Java is installed, we can create a tomcat user, which will be used to run the
Tomcat service.
Next, create a new tomcat user. We'll make this user a member of the tomcat group,
with a home director of /opt/tomcat (where we will install Tomcat), and with a shell
of /bin/false (so nobod can log into the account):
2 de 25 9/11/17 09:16
How To Install Apache Tomcat 8 on Ubuntu 16.0... https://www.digitalocean.com/community/tutoria...
Find the latest version of Tomcat 8 at the Tomcat 8 Downloads page. At the time of
writing, the latest version is 8.5.5, but ou should use a later stable version if it is
available. Under the Binar Distributions section, then under the Core list, cop the link
to the "tar.gz".
Next, change to the /tmp director on our server. This is a good director to
download ephemeral items, like the Tomcat tarball, which we won't need after
extracting the Tomcat contents:
$ cd /tmp
Use curl to download the link that ou copied from the Tomcat website:
$ curl -O http://apache.mirrors.ionfish.org/tomcat/tomcat-8/v8.5.5/bin/apache-to
We will install Tomcat to the /opt/tomcat director. Create the director, then extract
the archive to it with these commands:
Next, we can set up the proper user permissions for our installation.
3 de 25 9/11/17 09:16
How To Install Apache Tomcat 8 on Ubuntu 16.0... https://www.digitalocean.com/community/tutoria...
Give the tomcat group ownership over the entire installation director:
Next, give the tomcat group read access to the conf director and all of its contents,
and execute access to the director itself:
Make the tomcat user the owner of the webapps , work , temp , and logs
directories:
Now that the proper permissions are set up, we can create a sstemd service file to
manage the Tomcat process.
Tomcat needs to know where Java is installed. This path is commonl referred to as
"JAVA_HOME". The easiest wa to look up that location is b running this command:
$ sudo update-java-alternatives -l
Output
java-1.8.0-openjdk-amd64 1081 /usr/lib/jvm/java-1.8.0-openjdk-amd64
The correct JAVA_HOME variable can be constructed b taking the output from the last
column (highlighted in red) and appending /jre to the end. Given the example above,
the correct JAVA_HOME for this server would be:
Sign up for our newsletter. ×
Get the latest tutorials on SysAdmin and open source topics.
SCROLL TO TOP
ign Up
4 de 25 9/11/17 09:16
How To Install Apache Tomcat 8 on Ubuntu 16.0... https://www.digitalocean.com/community/tutoria...
JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre
With this piece of information, we can create the sstemd service file. Open a file called
tomcat.service in the /etc/systemd/system director b tping:
Paste the following contents into our service file. Modif the value of JAVA_HOME if
necessar to match the value ou found on our sstem. You ma also want to modif
the memor allocation settings that are specified in CATALINA_OPTS :
/etc/sstemd/sstem/tomcat.service
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target
[Service]
Type=forking
Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always
Sign up for our newsletter. ×
Get the latest tutorials on SysAdmin and open source topics.
SCROLL TO TOP
ign Up
5 de 25 9/11/17 09:16
How To Install Apache Tomcat 8 on Ubuntu 16.0... https://www.digitalocean.com/community/tutoria...
[Install]
WantedBy=multi-user.target
Next, reload the sstemd daemon so that it knows about our service file:
Before we do that, we need to adjust the firewall to allow our requests to get to the
service. If ou followed the prerequisites, ou will have a ufw firewall enabled
currentl.
Tomcat uses port 8080 to accept conventional requests. Allow traffic to that port b
tping:
With the firewall modified, ou can access the default splash page b going to our
Sign up for our newsletter. ×
Get the latest tutorials on SysAdmin and open source topics.
domain or IP address followed b :8080 in a web browser:
SCROLL TO TOP
ign Up
6 de 25 9/11/17 09:16
How To Install Apache Tomcat 8 on Ubuntu 16.0... https://www.digitalocean.com/community/tutoria...
You will see the default Tomcat splash page, in addition to other information. However,
if ou click the links for the Manager App, for instance, ou will be denied access. We
can configure that access next.
If ou were able to successfull accessed Tomcat, now is a good time to enable the
service file so that Tomcat automaticall starts at boot:
You will want to add a user who can access the manager-gui and admin-gui (web
apps that come with Tomcat). You can do so b defining a user, similar to the example
below, between the tomcat-users tags. Be sure to change the username and
password to something secure:
<tomcat-users . . .>
<user username="admin" password="password" roles="manager-gui,admin-gui"/>
</tomcat-users>
B default, newer versions of Tomcat restrict access to the Manager and Host Manager
Sign up for our newsletter. ×
Get the latest tutorials on SysAdmin and open source topics.
apps to connections coming from the server itself. ince we are installing on a remote
SCROLL TO TOP
machine, ou will probabl want to remove or alter this restriction.
ignTo
Upchange the IP
7 de 25 9/11/17 09:16
How To Install Apache Tomcat 8 on Ubuntu 16.0... https://www.digitalocean.com/community/tutoria...
Inside, comment out the IP address restriction to allow connections from anwhere.
Alternativel, if ou would like to allow access onl to connections coming from our
own IP address, ou can add our public IP address to the list:
8 de 25 9/11/17 09:16
How To Install Apache Tomcat 8 on Ubuntu 16.0... https://www.digitalocean.com/community/tutoria...
The page ou see should be the same one ou were given when ou tested earlier:
Let's take a look at the Manager App, accessible via the link or
http://server_domain_or_IP:8080/manager/html . You will need to enter the
account credentials that ou added to the tomcat-users.xml file. Afterwards, ou
should see a page that looks like this:
9 de 25 9/11/17 09:16
How To Install Apache Tomcat 8 on Ubuntu 16.0... https://www.digitalocean.com/community/tutoria...
top, Reload, Deplo, and Undeplo here. You can also run some diagnostics on our
apps (i.e. find memor leaks). Lastl, information about our server is available at the
ver bottom of this page.
Now let's take a look at the Host Manager, accessible via the link or
http://server_domain_or_IP:8080/host-manager/html/ :
From the Virtual Host Manager page, ou can add virtual hosts to serve our
applications from.
Conclusion
Your installation of Tomcat is complete! Your are now free to deplo our own Java web
applications!
Currentl, our Tomcat installation is functional, but entirel unencrpted. This means
that all data, including sensitive items like passwords, are sent in plain text that can be
intercepted and read b other parties on the internet. In order to prevent this from
happening, it is strongl recommended that ou encrpt our connections with L.
You can find out how to encrpt our connections to Tomcat b following this guide.
10 de 25 9/11/17 09:16
How To Install Apache Tomcat 8 on Ubuntu 16.0... https://www.digitalocean.com/community/tutoria...
Related Tutorials
How to et Up hin erver on Ubuntu 16.04
67 Comments
11 de 25 9/11/17 09:16
How To Install Apache Tomcat 8 on Ubuntu 16.0... https://www.digitalocean.com/community/tutoria...
Leave a comment...
Log In to Comment
0 To ensure the Tomcat service re-starting at boot, ou have to enable it:
1 Hello,
For me (in ubuntu 14 (i know this is for ubuntu 16)), in the step 4 :
sudo chmod g+r conf/* ==> does not work "No file or director".
Is it normal ?
0 Before the step 4 when using curl -0 " archive_URL " is indicated
curl -O http://apache.mirrors.ionfish.org/tomcat/tomcat-8/v8.0.36/bin/a
12 de 25 9/11/17 09:16
How To Install Apache Tomcat 8 on Ubuntu 16.0... https://www.digitalocean.com/community/tutoria...
0 Actuall if ou are using the extra sudo user from digital ocean's first setup guide
("demo"), then check if that user is part of the "tomcat" group. If ou add them to
the tomcat group, then it should work. I'm not sure if this is an oversight in the
article.
It looks like there were some changes to the wa that the Tomcat files were
being packaged b Apache that caused some of the commands to fail in more
recent installations. I've updated the guide to assign different permissions and
ownership in line with the suggestions here, and also made a few adjustments
to account for some other packaging changes (IP address restrictions). orr
for the inconvenience. Hopefull this will fix some of these issues.
13 de 25 9/11/17 09:16
How To Install Apache Tomcat 8 on Ubuntu 16.0... https://www.digitalocean.com/community/tutoria...
Although I am logged in as user (which has sudo privileges) still I am getting Permission
denied error. I have also changed the ownership of /opt/tomcat/bin director to the
user from which I am firing those commands, still the error is coming.
0 Hello,
I've got this error and can not shutdown the tomcat properl.
Is there a wa to solve it?
14 de 25 9/11/17 09:16
How To Install Apache Tomcat 8 on Ubuntu 16.0... https://www.digitalocean.com/community/tutoria...
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.catalina.startup.Bootstrap.stopServer(Bootstrap.java:408)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:497)
Thank ou.
5 If ou are having problems getting tomcat 8 to start and getting this error
then ou might want to give tomcat user ownership of the whole tomcat director:
ee http://unix.stackexchange.com/questions/235891/tomcat-8-will-not-start-after-
initial-install
0 I have the same problem - is it safe to make the tomcat user the owner of the
whole /tomcat folder?
15 de 25 9/11/17 09:16
How To Install Apache Tomcat 8 on Ubuntu 16.0... https://www.digitalocean.com/community/tutoria...
0 Thanks a lot!!!
I've updated the guide to assign different permissions and ownership in line
with the suggestions here, and also made a few adjustments to account for
some other packaging changes (IP address restrictions). orr for the
inconvenience. Hopefull this will fix some of these issues.
0 Hi
Just installed Tomcat 8on Ubuntu 16.04 . Changed the Tomcat-user.xml file too with
manager-gui role and changed the password , but I keep getting the 403 Access
Denied Page when I click the Manager App from the Tomcat 8
Thanks
I've updated the guide to assign different permissions and ownership in line with
the suggestions here, and also made a few adjustments to account for some other
Sign up for our newsletter.
Get the latest tutorials on SysAdmin and open source topics. ×
packaging changes (IP address restrictions). orr for the inconvenience. Hopefull
SCROLL TO TOP
this will fix some of these issues. ign Up
16 de 25 9/11/17 09:16
How To Install Apache Tomcat 8 on Ubuntu 16.0... https://www.digitalocean.com/community/tutoria...
The specific changes ou'll want to look into are the ones dealing with the
context.xml files.
0 Hi, i have been tring to figure this out for a week but unable to get Tomcat 8 to start
while following this guide.
--
-- Unit tomcat.service has failed.
--
-- The result is failed.
Aug 22 00:12:17 aimed-ubuntu-blr systemd[1]: tomcat.service: Unit entered
Aug 22 00:12:17 aimed-ubuntu-blr systemd[1]: tomcat.service: Failed with r
Aug 22 00:12:27 aimed-ubuntu-blr systemd[1]: tomcat.service: Service hold-
Aug 22 00:12:27 aimed-ubuntu-blr systemd[1]: Stopped Apache Tomcat Web App
-- Subject: Unit tomcat.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit tomcat.service has finished shutting down.
Aug 22 00:12:27 aimed-ubuntu-blr systemd[1]: Starting Apache Tomcat Web Ap
-- Subject: Unit tomcat.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit tomcat.service has begun starting up.
Aug 22 00:12:27 aimed-ubuntu-blr systemd[26177]: tomcat.service: Failed at
-- Subject: Process /opt/tomcat/bin/startup.sh could not be executed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- The process /opt/tomcat/bin/startup.sh could not be executed and failed
--
-- The error number returned by this process is 13.
Aug 22 00:12:27 aimed-ubuntu-blr systemd[1]: tomcat.service: Control proce
Aug 22 00:12:27 aimed-ubuntu-blr systemd[1]: Failed to start Apache Tomcat
-- Subject: Unit tomcat.service has failed
-- Defined-By: systemd
Sign up for our newsletter.
Get the latest tutorials on SysAdmin and open source topics.
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel ×
SCROLL TO TOP
-- ign Up
17 de 25 9/11/17 09:16
How To Install Apache Tomcat 8 on Ubuntu 16.0... https://www.digitalocean.com/community/tutoria...
0 Had the same problem! followed @uncleboni 's advice and gave ownership of
/opt/tomcat to 'tomcat' user. The problem is gone now!
At least it starts now, but what about securit?
I've updated the guide to assign different permissions and ownership in line
with the suggestions here, and also made a few adjustments to account for
some other packaging changes (IP address restrictions). orr for the
inconvenience. Hopefull this will fix some of these issues.
0 Im having a issue that when I restarted the Ubuntu 16.04 running Tomcat 8, it would
not let me access...
I saw that it was binding it to IPv6 so I disabled it a kernel level. Now it is listening to
IPv4 but it still does not let me access.
18 de 25 9/11/17 09:16
How To Install Apache Tomcat 8 on Ubuntu 16.0... https://www.digitalocean.com/community/tutoria...
-- Defined-B: sstemd
-- upport: http://lists.freedesktop.org/mailman/listinfo/sstemd-devel
-- Unit tomcat.service has begun starting up.
ep 13 17:39:33 Bab-Concept sstemd[2887]: tomcat.service: Failed at step EXEC
-- ubject: Process /opt/tomcat/bin/startup.sh could not be executed
-- Defined-B: sstemd
19 de 25 9/11/17 09:16
How To Install Apache Tomcat 8 on Ubuntu 16.0... https://www.digitalocean.com/community/tutoria...
tomcat it responded that Job for tomcat.service failed because the control process
exited with error code. ee "sstemctl status tomcat.service" and "journalctl -xe" for
details.
mobi@mobi-near:/tmp$ cd /opt/tomcat
mobi@mobi-near:/opt/tomcat$ sudo chgrp -R tomcat conf
mobi@mobi-near:/opt/tomcat$ sudo chmod g+rwx conf
mobi@mobi-near:/opt/tomcat$ sudo chmod g+r conf/*
chmod: cannot access 'conf/*': No such file or directory
mobi@mobi-near:/opt/tomcat$ sudo chmod g+r conf/opt/tomcat
chmod: cannot access 'conf/opt/tomcat': No such file or directory
mobi@mobi-near:/opt/tomcat$ sudo chmod g+r conf /opt/tomcat
mobi@mobi-near:/opt/tomcat$ sudo chown -R tomcat webapps/ work/ temp/ logs/
mobi@mobi-near:/opt/tomcat$ sudo update-java-alternatives -l
java-8-oracle 1 /usr/lib/jvm/java-8-oracle
mobi@mobi-near:/opt/tomcat$ ^C
mobi@mobi-near:/opt/tomcat$ /usr/lib/jvm/java-8-oracle/jre
bash: /usr/lib/jvm/java-8-oracle/jre: Is a directory
mobi@mobi-near:/opt/tomcat$ sudo nano /etc/systemd/system/tomcat.service
Use "fg" to return to nano.
20 de 25 9/11/17 09:16
How To Install Apache Tomcat 8 on Ubuntu 16.0... https://www.digitalocean.com/community/tutoria...
I want to know what was the mistake done b me . Is problem no.2 arrised due to wrong path
mentioned in 1 ).
the file tomcat.service was not present in the director mentioned so I opened it using
Terminal & made changes in the terminal
1 @raghubatta007 He there. I've just had a chance to go through the guide again
and check this out. It looks like there were some changes to the wa that the
Tomcat files were being packaged b Apache that caused some of the commands
to fail in more recent installations. I apologize that the instructions were not
working for awhile.
I've updated the guide to assign different permissions and ownership in line with
the suggestions here, and also made a few adjustments to account for some other
packaging changes (IP address restrictions). orr for the inconvenience. Hopefull
this will fix some of these issues.
0 Hello there,
Thanks for giving our precious time for Repling so quickl . I have
successfull Installed & configured Apache Tomcat .
Can ou please tell me how can I install Oracle 10g database in Ubuntu 16.04 .
even its now not supported b Oracle.:)
Thanks
1 I have followed these instructions to a T, and have also read through all comments and
a couple stackexchange 'fixes.'
m sstemd file works fine, tomcat starts and is accessible at m droplets ip:8080.
BUT, when I check sudo sstemctl status tomcat, i get the following:
Sign up for our newsletter.
Get the latest tutorials on SysAdmin and open source topics. ×
SCROLL TO TOP
● tomcat.service - Apache Tomcat Web Application
ign UpContainer
21 de 25 9/11/17 09:16
How To Install Apache Tomcat 8 on Ubuntu 16.0... https://www.digitalocean.com/community/tutoria...
This causes tomcat to stop. After rebooting the server everthing works again.
I've fixed permissions on shutdown.sh and all files in bin using:
0 he gus anbod can help me out with this? im new to linux so kinda lost and stuff
i keep getting chown: invalid user: ‘tomcat’ when i do the step 4
sudo chown -R tomcat webapps/ work/ temp/ logs/
0 [deleted]
0 Are ou sure ou created our user correctl ? ou can check that it exists, e.g. b
running "sudo cat /etc/passwd" (the last output line should be something like
"tomcat:x:1001:1001::/opt/tomcat:/bin/false")
22 de 25 9/11/17 09:16
How To Install Apache Tomcat 8 on Ubuntu 16.0... https://www.digitalocean.com/community/tutoria...
Great tutorial. Explainations are short but clear and concise. Huge thanks gus !
0 If anone is tring to write files and getting permission denied errors, this is what I did
to fix:
WorkingDirectory=/opt/tomcat/work
For example, this file has the following not found in the CentO 7 example:
Group=tomcat
UMask=0007
Sign up for our newsletter.
Restartec=10
Get the latest tutorials on SysAdmin and open source topics. ×
SCROLL TO TOP
Restart=alwas ign Up
23 de 25 9/11/17 09:16
How To Install Apache Tomcat 8 on Ubuntu 16.0... https://www.digitalocean.com/community/tutoria...
Are these differences unique to Ubuntu, or should the be in the CentO 7 version as well?
Wh are the needed?
0 Out of curiosit, wh is this preferred over sudo apt-get install tomcat8 ?
24 de 25 9/11/17 09:16
How To Install Apache Tomcat 8 on Ubuntu 16.0... https://www.digitalocean.com/community/tutoria...
Copright © 2017 DigitalOcean™ Inc.
Distros & One-Click Apps Terms, Privac, & Copright ecurit Report a Bug
Write for DigitalOcean hop
25 de 25 9/11/17 09:16