How to Install and Configure Apache Tomcat 9 in CentOS

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Ravi Saive

I am Ravi Saive, creator of TecMint. A Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My Servers runs on Open Source Platform called Linux. Follow Me: Twitter, Facebook and Google+

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

24 Responses

  1. Martin Schaible says:

    I removed MC, but it wasn’t the reason.
    It is really strange, that no errors where generated, only a zero byte length log file “catalina.out” was generated.

    • Ravi Saive says:

      @Martin,

      Thanks for your efforts, let’s give a final try by creating a systemd unit file, with this you can start, stop and enable the tomcat service..

      Create and open the unit file by running this command:

      # vi /etc/systemd/system/tomcat.service
      

      Paste in the following script. Make sure to modify the memory allocation and path to tomcat installation settings that are specified in CATALINA_OPTS, CATALINA_HOME and CATALINA_PID:

      # Systemd unit file for tomcat
      [Unit]
      Description=Apache Tomcat Web Application Container
      After=syslog.target network.target
      
      [Service]
      Type=forking
      
      Environment=JAVA_HOME=/usr/lib/jvm/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/./urandom'
      
      ExecStart=/opt/tomcat/bin/startup.sh
      ExecStop=/bin/kill -15 $MAINPID
      
      User=tomcat
      Group=tomcat
      UMask=0007
      RestartSec=10
      Restart=always
      
      [Install]
      WantedBy=multi-user.target
      

      Save and exit. This script tells the server to run the Tomcat service as the tomcat user, with the settings specified.

      Now reload Systemd to load the Tomcat unit file and start & enable the service.

      # systemctl daemon-reload
      # systemctl start tomcat
      # systemctl enable tomcat
      
  2. Martin Schaible says:

    Thanks for this helpful tutorial. I used this article with other sources of information to get a clean installation.

    In my case Tomcat does not start, if i execute “./startup.sh” which goes to “catalina.sh start“. Only an empty log file “catalina.out” was generated.
    If i run “./catalina.sh run“, tomcat starts and works. In this case, Tomcat runs in the current window.

    Now something weird: If the “Midnight Commander” is active and i run “./startup.sh“, it works!

    Looks kind of a shell problem.

    I’m really stuck, any idea where to look?

    Cheers!

    • Ravi Saive says:

      @Martin,

      This is something really weird thing, I came across, have you tried on different terminal shell?

      • Martin Schaible says:

        I have a standard CentOS 7 installation like others have. i’m not really sure, if it a good idea to change the shell systemwide. Keep in mind, that tomcat behaves the same, if i try to start the service instead on the command prompt.

Got something to say? Join the discussion.

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.