AMP AMP

How to install Tomcat9 on Ubuntu 16.04

To install Tomcat9 on Ubuntu 16.04

Apache Tomcat is an open source web hosting server and servlet container from Apache Software Foundation. It executes Java servlets and renders Web pages for the Java-based web application. In fact, Apache Tomcat is one of the most popularly used web servers among the java developers. It is really simple to install Apache Tomcat on Ubuntu 16.04, and this article covers the ground on the same process.

Installing Tomcat9

It is really very essential to install Java, so make sure you run the following command.

root@linuxhelp11:~# apt-get install default-jdk
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  gnome-software-common libgtkspell3-3-0
Use ' sudo apt autoremove'  to remove them.
The following additional packages will be installed:
  ca-certificates-java default-jdk-headless default-jre default-jre-headless
  fonts-dejavu-extra java-common libgif7 libice-dev libpthread-stubs0-dev
  libsm-dev libx11-dev libx11-doc libxau-dev libxcb1-dev libxdmcp-dev
  libxt-dev openjdk-8-jdk openjdk-8-jdk-headless openjdk-8-jre
  openjdk-8-jre-headless x11proto-core-dev x11proto-input-dev x11proto-kb-dev
  xorg-sgml-doctools xtrans-dev
.
.
.
Updating certificates in /etc/ssl/certs...
0 added, 0 removed  done.
Running hooks in /etc/ca-certificates/update.d...

done.
done.


Once it is installed, you shall check the version of Java which you’ ve just installed. Run the following command for the same purpose.

root@linuxhelp11:~# java -version
openjdk version " 1.8.0_151" 
OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)


Once it is done, you need to create a user for Tomcat. Run the command for that.

root@linuxhelp11:~# useradd -r tomcat9 --shell /bin/false

Then enter into the opt location through the following command.

root@linuxhelp11:~# cd /opt  

Now, you shall download tomcat9 package by using the wget command in the following manner.

root@linuxhelp11:/opt# wget http://www-eu.apache.org/dist/tomcat/tomcat-9/v9.0.1/bin/apache-tomcat-9.0.1.tar.gz
--2017-11-19 05:39:43--  http://www-eu.apache.org/dist/tomcat/tomcat-9/v9.0.1/bin/apache-tomcat-9.0.1.tar.gz
Resolving www-eu.apache.org (www-eu.apache.org)... 195.154.151.36, 2001:bc8:2142:300::
Connecting to www-eu.apache.org (www-eu.apache.org)|195.154.151.36|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9397803 (9.0M) [application/x-gzip]
Saving to: ‘ apache-tomcat-9.0.1.tar.gz’ 

apache-tomcat-9.0.1 100%[===================> ]   8.96M  9.51MB/s    in 0.9s    

2017-11-19 05:40:35 (9.51 MB/s) - ‘ apache-tomcat-9.0.1.tar.gz’  saved [9397803/9397803]

Then, extract the downloaded file as follows.

root@linuxhelp11:/opt# tar -zxf apache-tomcat-9.0.1.tar.gz

After that, you need to create a symbolic link for extracted directory in the following manner.

root@linuxhelp11:/opt# ln -s apache-tomcat-9.0.1 tomcat-latest

Later, you need to change the ownership of the extracted directory.

root@linuxhelp11:/opt# chown -R tomcat9: tomcat-latest apache-tomcat-9.0.1

Once it is done, you need to create a user for manager and admin in tomcat-user file. Using the vim editor, create a new file.

root@linuxhelp11:/opt# vim tomcat-latest/conf/tomcat-users.xml

And, in that file, you need to add the following lines.

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

Once the above part is over, you need to make an entry to allow the server. So open the file.

root@linuxhelp11:/opt# vim tomcat-latest/webapps/manager/META-INF/context.xml

And in that file, you need to give your server ip.

< Valve className=" org.apache.catalina.valves.RemoteAddrValve" 
         allow=" 127.d+.d+.d+|::1|0:0:0:0:0:0:0:1|<  server ip > "  /> 

You should also add your server ip in another location as well. And for that, go to the following location.

root@linuxhelp11:/opt# vim tomcat-latest/webapps/host-manager/META-INF/context.xml

And in that file, modify the server ip to yours.

< Valve className=" org.apache.catalina.valves.RemoteAddrValve" 
         allow=" 127.d+.d+.d+|::1|0:0:0:0:0:0:0:1|<  server ip > "  /> 

Next, you need to configure the daemon file to start and stop tomcat service. So, open the file.

root@linuxhelp11:/opt# vim /etc/systemd/system/tomcat.service

And add the following lines to it.

[Unit]
Description=Tomcat9
After=network.target

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

Environment=CATALINA_PID=/opt/tomcat-latest/tomcat9.pid
Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
Environment=CATALINA_HOME=/opt/tomcat-latest
Environment=CATALINA_BASE=/opt/tomcat-latest
Environment=" CATALINA_OPTS=-Xms512m -Xmx512m" 
Environment=" JAVA_OPTS=-Dfile.encoding=UTF-8 -Dnet.sf.ehcache.skipUpdateCheck=true -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+UseParNewGC" 

ExecStart=/opt/tomcat-latest/bin/startup.sh
ExecStop=/opt/tomcat-latest/bin/shutdown.sh

[Install]
WantedBy=multi-user.target

Once it is done, you need to reload the daemon as follows.

root@linuxhelp11:/opt# systemctl daemon-reload

Then, start the Tomcat service.

root@linuxhelp11:/opt# systemctl start tomcat


And, enable it as follows.

root@linuxhelp11:/opt# systemctl enable tomcat
Created symlink from /etc/systemd/system/multi-user.target.wants/tomcat.service to /etc/systemd/system/tomcat.service.

Now, open a browser and give localhost:8080 as the URL . The home page of Tomcat appears on your screen.

If you want to open the manager app, then click on it.


And give your login credentials in the popup that appears.

The Manager page of Tomcat now appears.



If you want to open the VirtualHost for admin panel, then click on Host manage.

In that popup, give your credentials.

The Host page now appears.


With this, the installation of Tomcat9 comes to an end.

Tag : Ubuntu Tomcat
FAQ
Q
How to download the Tomcat9 package on Ubuntu?
A
Run the following command:
# wget http://www-eu.apache.org/dist/tomcat/tomcat-9/v9.0.1/bin/apache-tomcat-9.0.1.tar.gz
Q
How to check the current version of java?
A
USe the following command:
# java -version
Q
What is Tomcat9 on Ubuntu?
A
Apache Tomcat is an open source web hosting server and servlet container from Apache Software Foundation. It executes Java servlets and renders Web pages for the Java-based web application. In fact, Apache Tomcat is one of the most popularly used web servers among the java developers.
Q
What's the difference between JK and mod_jk ?
A
JK is a project covering web-servers to Tomcat connectors, whereas mod_jk is the Apache module developped in JK.

Domino webserver support is implemented on JK, using a redirector called dsa
Q
Which protocol should I use? Ajp12 or Ajp13?
A
Ajp13 is a newer protocol, it's faster, and it works better with SSL. You almost certainly want to use it now that ajp12 is deprecated.

Also ajp13 is supported by all Apache Tomcat includin