Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»General Articles»How to Install Tomcat 8.5 on CentOS/RHEL 8

    How to Install Tomcat 8.5 on CentOS/RHEL 8

    By RahulDecember 27, 20193 Mins ReadUpdated:February 18, 2022

    Apache Tomcat 8.5 is the latest version available for the installation of the Tomcat 8 series. Tomcat is an open-source web server for the Java-based applications developed by the Apache Foundation. We use Tomcat for deploying Java Servlet and JSP applications. To know more about the Apache Tomcat visit apache official site http://tomcat.apache.org/.

    Advertisement

    Prerequisites

    • shell access
    • sudo priviledged account access

    Step 1 – Install Java

    Java is the primary requirement for running Tomcat 8.5 on CentOS 8 Linux system. Make sure you have Java 8 or higher version installed in your system. If you don’t’ have Java installed, use the following command to install java (OpenJDK) on your system.

    sudo dnf install openjdk
    

    Then check the installed Java version

    java -version
    
    openjdk version "11.0.4" 2019-07-16 LTS
    OpenJDK Runtime Environment 18.9 (build 11.0.4+11-LTS)
    OpenJDK 64-Bit Server VM 18.9 (build 11.0.4+11-LTS, mixed mode, sharing)
    

    Step 2 – Create Tomcat User

    Many of the system administrators are run the Tomcat server with root user. Which is not the correct way for security purposes. So, I always prefer to create a separate user account to run the Tomcat server on the Linux system.

    sudo useradd -m -d /opt/tomcat -U -s /bin/false tomcat
    

    The above command will create user “tomcat” with the group “tomcat”.

    Step 3 – Download Tomcat 8

    Download Apache Tomcat archive file from Apache tomcat official download page. You can use below wget command to download it.

    wget https://dlcdn.apache.org/tomcat/tomcat-8/v8.5.75/bin/apache-tomcat-8.5.75.tar.gz
    

    Then extract the archive file and copy all the files under tomcat home directory

    tar xzf apache-tomcat-8.5.75.tar.gz
    sudo mv apache-tomcat-8.5.75/* /opt/tomcat/
    

    Also, set the proper ownership of all files.

    sudo chown -R tomcat:tomcat /opt/tomcat/
    

    Step 4 – Enable Host/Manager for Remote IP

    The latest Tomcat versions do not allow manager and host-manager interface for remote users. You can access them from the localhost only. To enable access to these pages for the remote system, allow IP or IP range in the application-specific context.xml file. The files are as following:

    • Manager – /opt/tomcat/webapps/manager/META-INF/context.xml
    • Host Manager – /opt/tomcat/webapps/host-manager/META-INF/context.xml

    Edit the above files one byte one and add your IP address like 192.168.1.10 in the below screenshot.

    Tomcat enable remote access

    Step 5 – Setup User Accounts

    Finally we need to create user accounts to secure and access admin/manager pages. Edit conf/tomcat-users.xml file in your editor and paste inside <tomcat-users> </tomcat-users> tags.

    <!-- user manager can access only manager section -->
    <role rolename="manager-gui" />
    <user username="manager" password="_SECRET_PASSWORD_" roles="manager-gui" />
    
    <!-- user admin can access manager and admin section both -->
    <role rolename="admin-gui" />
    <user username="admin" password="_SECRET_PASSWORD_" roles="manager-gui,admin-gui" />
    

    Step 6 – Create Tomcat Start Script

    Tomcat provides bash scripts for start or stop service. But you can also create a startup script to manage Tomcat via systemctl command. Create a tomcat.service file with the following content:

    sudo vim /etc/systemd/system/tomcat.service
    
    [Unit]
    Description=Tomcat 8.5
    After=network.target
    
    [Service]
    Type=forking
    
    User=tomcat
    Group=tomcat
    
    Environment="JAVA_HOME=/usr/lib/jvm/jre"
    Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"
    Environment="CATALINA_BASE=/opt/tomcat"
    Environment="CATALINA_HOME=/opt/tomcat"
    Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"
    Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
    
    ExecStart=/opt/tomcat/bin/startup.sh
    ExecStop=/opt/tomcat/bin/shutdown.sh
    
    [Install]
    WantedBy=multi-user.target
    

    Reload the systemd daemon service to apply changes

    sudo systemctl daemon-reload
    

    Then, enable and start Tomcat service on your system

    sudo systemctl enable tomcat.service
    sudo systemctl start tomcat.service
    

    Step 7 – Access Tomcat in Browser

    Tomcat server works on port 8080 default. To access Tomcat on the web browser by connecting your server on port 8080.

    If you are connecting from the local machine then use the localhost. To connect from remote machine use IP address of the system with port:

     http://localhost:8080 

    Install Tomcat 8 on CentOS 8

    Conclusion

    You have a running Tomcat 8.5 server on your CentOS 8 system. You may also need to create a Virtual host or configure a SSL certificate in Tomcat.

    CentOS 8 tomcat Tomcat 8
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Error: EACCES: permission denied, scandir (Resolved)

    How To Install Python 3.11 on Ubuntu 22.04 / 20.04

    Excluding URLs from ProxyPass in Apache

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Error: EACCES: permission denied, scandir (Resolved)
    • How To Install Python 3.11 on Ubuntu 22.04 / 20.04
    • How to Install Python 3.11 on Amazon Linux 2
    • An Introduction to the “./configure” Command: Compiling Source Code in Linux
    • How to Install PHP 8.x on Pop!_OS
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.