How to install Tomcat in Freebsd

To install Tomcat in FreeBSD

Tomcat is an open-source, web server that implements several Java EE specifications. It includes Java Servlet, JavaServer Pages (JSP), Java EL and Web Socket. In this article we will learn how to install Tomcat in FreeBSD.

Installing Tomcat

Utilize the following command to update the repository using “ pkg update” command.

root@linuxhelp:~ # pkg update -f 
Updating FreeBSD repository catalogue...
Fetching meta.txz: 100%    944 B   0.9kB/s    00:01    
Fetching packagesite.txz: 100%    6 MiB 321.2kB/s    00:18    
Processing entries: 100%
FreeBSD repository update completed. 25472 packages processed.


Then install Tomcat by using the following command.

root@linuxhelp:~ # pkg install tomcat8 
Updating FreeBSD repository catalogue...
FreeBSD repository is up-to-date.
All repositories are up-to-date.
Updating database digests format: 100%
New version of pkg detected  it needs to be installed first.
.
.
.
[1/5] Installing java-zoneinfo-2016.f...
[1/5] Extracting java-zoneinfo-2016.f: 100%
[2/5] Installing javavmwrapper-2.5_2...
[2/5] Extracting javavmwrapper-2.5_2: 100%
[3/5] Installing openjdk8-8.102.14_1...
[3/5] Extracting openjdk8-8.102.14_1: 100%
[4/5] Installing jakarta-commons-daemon-1.0.15...
[4/5] Extracting jakarta-commons-daemon-1.0.15: 100%
[5/5] Installing tomcat8-8.0.36...
[5/5] Extracting tomcat8-8.0.36: 100%
Message from openjdk8-8.102.14_1:
======================================================================

This OpenJDK implementation requires fdescfs(5) mounted on /dev/fd and
procfs(5) mounted on /proc.

If you have not done it yet, please do the following:

    mount -t fdescfs fdesc /dev/fd
    mount -t procfs proc /proc

To make it permanent, you need the following lines in /etc/fstab:

    fdesc    /dev/fd        fdescfs        rw    0    0
    proc    /proc        procfs        rw    0    0

======================================================================


After building Tomcat, mount the fdescfs and proc directories.

root@linuxhelp:~ # mount -t fdescfs fdesc /dev/fd
root@linuxhelp:~ # mount -t procfs proc /proc 


Then make it permanent mount on fstab file.

root@linuxhelp:~ # nano /etc/fstab  

fdesc           /dev/fd         fdescfs rw      0       0
proc            /proc           procfs  rw      0       0


Utilize the following command to rename the tomcat-users.xml file.

root@linuxhelp:~ # mv /usr/local/apache-tomcat-8.0/conf/tomcat-users.xml /usr/local/apache-tomcat-8.0/conf/tomcat-users.xml.backup 


Create tomcat-users.xml file and add the following lines to update the username and password.

root@linuxhelp:~ # nano /usr/local/apache-tomcat-8.0/conf/tomcat-users.xml 
< tomcat-users xmlns=" http://tomcat.apache.org/xml" 
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation=" http://tomcat.apache.org/xml
tomcat-users.xsd" 
version=" 1.0" > 
< role rolename=" manager-gui" /> 
< role rolename=" manager-script" /> 
< role rolename=" manager-jmx" /> 
< role rolename=" manager-status" /> 
< role rolename=" admin-gui" /> 
< role rolename=" admin-script" /> 
< user username=" admin"  password=" admin" 
roles=" manager-gui,manager-script,manager-jmx,manager-status,admin-gui,admin-sc$
< /tomcat-users> 


Next move to /usr/local/apache-tomcat-8.0/bin/ and check the files in it.

root@linuxhelp:~ # cd /usr/local/apache-tomcat-8.0/bin/
root@linuxhelp:/usr/local/apache-tomcat-8.0/bin # ls 
bootstrap.jar setclasspath.sh
catalina-tasks.xml shutdown.sh
catalina.sh startup.sh
commons-daemon-native.tar.gz tomcat-juli.jar
commons-daemon.jar tomcat-native.tar.gz
configtest.sh tool-wrapper.sh
daemon.sh version.sh
digest.sh


Finally run the startup.sh script to start the apache-tomcat service.

root@linuxhelp:/usr/local/apache-tomcat-8.0/bin # sh startup.sh 
Using CATALINA_BASE: /usr/local/apache-tomcat-8.0
Using CATALINA_HOME: /usr/local/apache-tomcat-8.0
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-8.0/temp
Using JRE_HOME: /usr/local
Using CLASSPATH: /usr/local/apache-tomcat-8.0/bin/bootstrap.jar:/usr/local/apache-tomcat-8.0/bin/tomcat-juli.jar
Tomcat started.


Unfold the browser and enter the URL http://< IP_address> :8080

Login into it using the credentials.

Enjoy using Tomcat server.

FAQ
Q
Where can I get more information ?
A
For JK 1.2.x , you should read :

For the impatients
Apache and JK
Domino and JK
IIS and JK
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 including 3.2.x , 3.3.x, 4.0.x, 4.1.x and the new tomcat 5.

Others Servlet engines like jetty have support for Ajp13.
Q
JK2 build report error about missing FIONBIO on Solaris 8?
A
In JK2 before v2.0.2, you should add

#define BSD_COMP

in top of jk/native2/common/jk_channel_socket.c to have Solaris build succeed.
Q
What is uses of Tomcat?
A
Tomcat is an open-source, web server that implements several Java EE specifications. It includes Java Servlet, JavaServer Pages (JSP), Java EL and Web Socket.
Q
Alternative for Tomcat ?
A
Oracle Weblogic, RedHat Jboss EAP, WebSphere Application server, Microsoft IIS, Oracle Glassfish Server, Nginx, SAP NetWeaver AS, etc.,