Installation and basic setup of Tomcat on FreeBSD Server

Apache Tomcat is open source software developed by the Apache Foundation. Tomcat is written in Java and was first released in 1999. James Duncan Davidson was its original founder, who was working as a software architect at the time. He started developing Apache Tomcat software to provide an implementation for servlets. What are servlets? In simple terms, a servlet is a server technology that helps process http requests and client responses.

Apache and Apache Tomcat are two famous web application servers used all over the world. Apache is a free open source website server that allows users to host and process dynamic websites, while Apache Tomcat is a servlet and JSP container server used to host Java web applications.

Both servers can work together, but their functions and goals are different. Apache is a static server that does not support servlets or JSP, while Apache Tomcat is only used to support Java web applications.

Additionally, Apache handles HTTP requests and Apache Tomcat is used to host Java code such as servlets and JSP. Apache can be used with PHP, Python, and other programming languages, while Apache Tomcat is used exclusively for Java applications.


1. system requirements

OS: FreeBSD 13.2
Hostname: ns7
IP Address: 192.168.5.2
Java version: openjdk17
Tomcat version: tomcat9


2. What is Apache and Apache Tomcat

Apache is a free web server that allows you to host web pages, scripts and other files on websites. Apache features high performance, reliability, and customization flexibility. Apache supports many protocols, including HTTP, HTTPS, and FTP.

Apache Tomcat is an application server designed to run Java applications in a Java Servlet and JavaServer Pages environment. Tomcat is an excellent choice for open source web applications such as forums and content management systems.

Apache Tomcat is used primarily for processing dynamic content, while Apache is used for processing static content. Apache can function as a front-end web server that accesses the Tomcat application server to process dynamic content.


3. Differences in functionality

Apache is a web server used to serve static pages and files such as HTML, CSS, JavaScript, and images. Apache can also be used to create simple CGI scripts in Perl or Python. On the other hand, Apache Tomcat is a servlet and JSP container. This means that Tomcat is used to execute Java code and applications built on the Java platform.

Additionally, Apache and Apache Tomcat differ in their protocol usage. Apache is usually used to handle HTTP requests while Tomcat is used to handle Java network requests over HTTPS.

It is also worth noting that Apache has advanced security and authentication configurations, which are important aspects for solving the problem of access to sensitive data. Tomcat also has security configuration options, but these are focused on web applications running on that server.

Overall, Apache and Apache Tomcat have different purposes and uses, but both can be useful web development and hosting tools depending on the user's needs.


4. Apache24 and Apache Tomcat Programming Languages

Like other web servers, Apache supports a variety of programming languages, from standard HTML and CSS to scripting languages such as JavaScript and PHP. In addition to the core language, Apache can work with programming languages such as Perl and Python, making it a versatile and flexible solution for web development.

Different from Apache, Apache Tomcat is a web application container designed to run dynamic pages using programming languages such as Java, JavaScript, and JSP. Apache Tomcat can be used to create and run web applications frequently used in e-commerce and other tasks that require dynamic website functionality. The following are the programming languages supported by both.
  1. Apache24: HTML, CSS, JavaScript, PHP, Perl, Python, dan lain-lain.
  2. Apache Tomcat: Java, JavaScript, JSP, dll.
The need to choose between Apache and Apache Tomcat may depend on the language used on the site. If the site only uses plain HTML, CSS, and JavaScript, you can choose Apache. If the site uses programming languages like Java and JSP, then Apache Tomcat would be a better choice.

In this article, we will try to install, configure and run Apache Tomcat on a FreeBSD 13.2 server.


5. Tomcat installation

Because Apache Tomcat uses the Java programming language, the main requirement for installing Apche Tomcat on our FreeBSD server is that Java is installed.

Also read:


The Tomcat installation in this article will use the FreeBSD ports system. With the ports system, all Tomcat dependencies can be installed completely. Below are the commands that can be typed for Tomcat installation.

root@ns1:~ # find /usr/ports/www/ -name tomcat\* -type d
/usr/ports/www/tomcat85
/usr/ports/www/tomcat9
/usr/ports/www/tomcat-native
/usr/ports/www/tomcat101
/usr/ports/www/tomcat-devel

The script above is used to search for the Tomct version on the FReeBSD ports system. This script will be very useful if we don't know the latest version of an application. From the results of the script display above, we will install "tomcat9".

root@ns1:~ # cd /usr/ports/www/tomcat9
root@ns1:/usr/ports/www/tomcat9 # make config
root@ns1:/usr/ports/www/tomcat9 # make install clean

The commands from the script above are used to install Tomcat, wait until the installation is complete.


6. Tomcat Configuration

The next step after the installation process is the configuration process. The first step to configure Tomcat is to create a Boot Start UP rc.d script. Type the following command in the /etc/rc.conf file.

root@ns1:~ # ee /etc/rc.conf
tomcat9_enable="YES"
tomcat9_java_home="/usr/local/openjdk17"
tomcat9_catalina_user="www"
tomcat9_catalina_home="/usr/local/apache-tomcat-9.0"
tomcat_catalina_base="/usr/local/apache-tomcat-9.0/conf/server.xml"
tomcat_catalina_tmpdir="/usr/local/apache-tomcat-9.0/temp"
tomcat9_classpath=""
tomcat9_java_opts=""
tomcat9_wait="30"
tomcat9_umask="0077"

Now we test whether Tomcat manages to run well on the FreeBSD server. Type the following script.

root@ns1:~ # service tomcat9 restart
Stopping tomcat9.
Waiting for PIDS: 3291.
Starting tomcat9.

From the results of the script above, if we read, Tomcat has successfully RUNNING on the FreeBSD server, we can see this from the words "Starting tomcat9". Then what else do we have to do after Tomcat RUNNING. The next step is the step we have been waiting for, namely running Tomcat.


7. Running Tomcat

The main configuration file or Tomcat config file is in the /usr/local/apache-tomcat-9.0/conf folder. By default Tomcat runs on Port 8080 and IP Address 127.0.0.1. Because the loopback IP cannot be remote from a Windows computer, we will replace the loopback IP 127.0.01 with the Private IP of our FreeBSD server computer, in this article the FreeBSD Private IP is 192.168.5.2. To change the IP, edit the file /usr/local/apache-tomcat-9.0/conf/server.xml.

By default IP 127.0.01 is not written in the script file. Below is an example of the original script before we edited it.

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

Now add IP 192.168.5.2, so the script will change as follows.

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443"
	       address="192.168.5.2"
               maxParameterCount="1000"
               />

For security reasons, access to the Tomcat Manager and Host Manager applications is locked to localhost (the server on which they are deployed), by default. Edit the file "/usr/local/apache-tomcat-9.0/conf/tomcat-users.xml".

<?xml version="1.0" encoding="UTF-8"?>
<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"/>
<user username="tomcat" password="router" roles="manager-gui"/>
<role rolename="manager-status"/>
<user username="robot" password="router" roles="manager-status"/>
<role rolename="admin-gui"/>
<user username="admin" password="router" roles="admin-gui"/>
</tomcat-users>

For the Tomcat Manager application, type the following script in the "/usr/local/apache-tomcat-9.0/webapps/host-manager/META-INF/context.xml" file.

<?xml version="1.0" encoding="UTF-8"?>
<Context antiResourceLocking="false" privileged="true" >
  <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
                   sameSiteCookies="strict" />
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|192.168.5.2"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|192.168.5.*"
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>

For the Tomcat Manager application, type the following script in the "/usr/local/apache-tomcat-9.0/webapps/manager/META-INF/context.xml" file.

<?xml version="1.0" encoding="UTF-8"?>
<Context antiResourceLocking="false" privileged="true" >
  <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
                   sameSiteCookies="strict" />
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|192.168.5.2"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|192.168.5.*" 
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>

The next step is to restart Tomcat.

root@ns1:~ # service tomcat9 restart
Stopping tomcat9.
Waiting for PIDS: 3291.
Starting tomcat9.

It's time to run Tomcat, because Tomcat is a Web server, to run Tomcat we open Google Chrome, Yandex or another browser. In the address bar menu, type the IP above, namely "http://192.168.5.2:8080". If there is nothing wrong with the configuration above, the Tomcat dashboard will appear in your web browser.


Apache Tomcat is a powerful, versatile and reliable web server that has proven useful in the world of web hosting. Its compatibility with Java applications, advanced features, and active community make it a top choice for many open source users. From small businesses to large enterprises, Apache Tomcat is trusted to deliver high performance, security, and scalability.
Iwan Setiawan

I Like Adventure: Mahameru Mount, Rinjani Mount I Like Writer FreeBSD

Post a Comment

Previous Post Next Post