Guide to installing and configuring Tomcat on Debian Linux 12.

Advertisement

What is Tomcat?

Tomcat is a web server and servlet container developed by the Apache Software Foundation. It is designed to run applications based on Java, as servlets and JavaServer Pages (JSP), which are key technologies in Java web development.

What is Tomcat used for?

Tomcat serves as a platform for running web applications written in Java. Allows:

  • Serving dynamic applications on the web.
  • Implement business logic through servlets.
  • Generate dynamic content using JSP.
  • Integrate with Java frameworks such as Spring and Hibernate.

Advantages of Tomcat

  1. Open source: Completely free and supported by a large community.
  2. Light: It is lighter than other Java Enterprise servers such as GlassFish or JBoss.
  3. Easy to integrate: Compatible with many popular Java tools and frameworks.
  4. Modularity: You can install only the necessary components.
  5. Flexibility: Configurable to meet different needs.

Benefits of using Tomcat

  • High performance: Capable of handling multiple concurrent requests.
  • Support for Java standards: Compliant with Java EE servlet and JSP specifications.
  • Reliability: Ideal for production applications thanks to its stability.
  • Cross-platform support: Works on any operating system that supports Java.

Tomcat Features

  1. Compliance with Java EE standards: Compatible with servlets and JSP.
  2. Extensibility: Supports modules and customization via configuration files.
  3. Remote management: Access through the web interface for administration.
  4. SSL support: : Connection security.
  5. Robust ecosystem: Compatible with CI/CD tools and other integrations

Installing Tomcat on Debian 12

  1. Prerequisites:
    • Make sure you have Java installed.
$ sudo apt install openjdk-17-jdk
$ java -version
openjdk version "17.0.13" 2024-10-15
OpenJDK Runtime Environment (build 17.0.13+11-Debian-2deb12u1)
OpenJDK 64-Bit Server VM (build 17.0.13+11-Debian-2deb12u1, mixed mode, sharing)

 Install Apache Tomcat 10 from repository

Debian includes Tomcat in its official repositories. Install it with:

$ sudo apt install tomcat10 tomcat10-admin tomcat10-user tomcat10-docs 

Check service status

After installation, the Tomcat service should start automatically. Check its status:

$ sudo systemctl status tomcat10

If it is not active, start it:

$ sudo systemctl start tomcat10

Enable the service to start automatically with the system:

$ sudo systemctl enable tomcat10

Tomcat 10 configuration (Conf) files are in the path /etc/tomcat10

$ ls /etc/tomcat10
Catalina  catalina.properties  context.xml  jaspic-providers.xml  logging.properties  policy.d  server.xml  tomcat-users.xml  web.xml

Edit the configuration file in /etc/tomcat10/server.xml:

$ sudo nano /etc/tomcat10/server.xml

Make sure the port is configured correctly:

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

Restart the Tomcat service:

$ sudo systemctl restart tomcat10

Basic commands to manage Tomcat

Start Tomcat:

$ sudo systemctl start tomcat10

Stop Tomcat:

$ sudo systemctl stop tomcat10

Restart Tomcat:

$ sudo systemctl restart tomcat10

View Tomcat status:

$ sudo systemctl status tomcat10

Access the Tomcat home page

By default, Tomcat listens on the port 8080. Access from a browser to:

Advertisement
http://&lt;tu_direccion_IP>:8080
http://localhost:8080

You should see the Apache Tomcat welcome page.

Configure the web administrator

  1. Enable access to the web administrator: Edit the user configuration file in /etc/tomcat10/tomcat-users.xml
$ sudo nano /etc/tomcat10/tomcat-users.xml

Add a user with administrator roles:

&lt;role rolename="manager-gui"/>
&lt;role rolename="admin-gui"/>
&lt;user username="tuusuario" password="tucontraseña" roles="manager-gui,admin-gui"/>

Save and close the file, then restart Tomcat:

$ sudo systemctl restart tomcat10

Access the administration panel:

http://&lt;tu_direccion_IP>:8080/manager/html
http://localhost:8080/manager/html

Enter the username and password you set up.

Connecting Tomcat 10 to Apache

To link Tomcat 10 with Apache on Debian 12, you can use the module mod_proxy from Apache. This will allow Apache to act as a reverse proxy for Tomcat.

Enable modules proxy and proxy_http:

$ sudo a2enmod proxy
$ sudo a2enmod proxy_http
$ sudo systemctl restart apache2

Configure Apache to redirect requests to Tomcat

Create a configuration file in Apache in /etc/apache2/sites-available/

$ sudo nano /etc/apache2/sites-available/tomcat.conf
&lt;VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    ProxyRequests Off
    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/
    &lt;Proxy *>
        Order deny,allow
        Allow from all
    &lt;/Proxy>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
&lt;/VirtualHost>

Enable Apache configuration and restart the service

$ sudo a2ensite tomcat.conf
$ sudo systemctl restart apache2

Check your settings Open your browser and go to:

http://localhost

You should see the Tomcat home page, indicating that Apache is correctly configured as a reverse proxy for Tomcat.

This configures Apache to redirect requests to Tomcat port 8080.

Tomcat's Relationship with Java, Servlets, and JSP

  • JSP (JavaServer Pages): A technology for developing dynamic web pages, similar to PHP, but based on Java.
  • Java: It is the base language for creating applications that run on Tomcat.
  • Servlets: These are Java components that process HTTP requests and generate dynamic responses.

Conclusions

Tomcat is an excellent choice for those looking for a reliable, lightweight web server compatible with Java-based applications. Thanks to its ease of use and high performance, it is widely used in both development and production environments. Learning to use Tomcat not only improves your server administration skills but also strengthens your understanding of the Java ecosystem.

Installing Apache Tomcat from the official Debian 12 repository is quick and easy. By taking advantage of precompiled packages, you'll ensure a standard and compatible configuration.

Our score
Click to rate this post!
(Votes: 0 Average: 0)
Advertisement
Share on social media...

Deja un comentario

Your email address will not be published. Required fields are marked *

Basic information on data protection
ResponsibleJavier Cachón Garrido +info...
PurposeManage and moderate your comments. +info...
LegitimationConsent of the concerned party. +info...
RecipientsAutomattic Inc., USA to spam filtering. +info...
RightsAccess, rectify and cancel data, as well as some other rights. +info...
Additional informationYou can read additional and detailed information on data protection on our page política de privacidad.

Este sitio usa Akismet para reducir el spam. Aprende cómo se procesan los datos de tus comentarios.

Scroll al inicio

Descubre más desde javiercachon.com

Suscríbete ahora para seguir leyendo y obtener acceso al archivo completo.

Seguir leyendo