Apache Tomcat (sometimes simply referred to as Tomcat) is a popular open-source web server software used to set up Java-based server environments. The technologies used in Tomcat include Java Servlet, Java Server Pages, Java Expression Language, and WebSocket and provides an HTTP server environment ideal for running Java-based applications. In this article, we will outline how to install Tomcat on your CentOS 7 server. Please note, in order to perform the instructions on this guide, you will need root SSH access to your VPS or Dedicated server.
Before you begin, make sure you have installed Java.
Topics Include:
Please note that this article only pertains to Private Cloud and Bare Metal servers. Also, Control Web Panel (CWP) users can install this in a few clicks.
Installing Apache Tomcat
- First, ensure your machine and all related packages are up-to-date with the following commands:
sudo yum install epel-release
sudo yum update -y && sudo reboot
- Next, create a tomcat user and add it to the tomcat group with the following commands:
sudo groupadd tomcat
sudo mkdir /opt/tomcat
sudo useradd -s /bin/nologin -g tomcat -d /opt/tomcat tomcat
- Next, change back to the home directory and download the Tomcat .tar file using the following commands:
cd ~
wget https://www-us.apache.org/dist/tomcat/tomcat-8/v8.0.33/bin/apache-tomcat-8.5.71.tar.gz
Note: You will want to check the official Apache website for the latest stable release of the Tomcat software.
- Once it has finished downloading, extract the Tomcat archive using the following command:
sudo tar -zxvf apache-tomcat-8.0.33.tar.gz -C /opt/tomcat --strip-components=1
- Once the extraction finishes, update the file permissions with the following commands:
cd /opt/tomcat
sudo chgrp -R tomcat conf
sudo chmod g+rwx conf
sudo chmod g+r conf/*
sudo chown -R tomcat logs/ temp/ webapps/ work/
sudo chgrp -R tomcat bin
sudo chgrp -R tomcat lib
sudo chmod g+rwx bin
sudo chmod g+r bin/*
- Next, you will need to set up a systemd unit file using the following command to open a text editor:
sudo nano /etc/systemd/system/tomcat.service
- With the text editor open, add the following code:
[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
[Install]WantedBy=multi-user.target - Press Crtl + X to save and quit the text editor.
- Next, you will need to install and enable the haveged utility for security using the following commands:
sudo yum install haveged
sudo systemctl start haveged.service
sudo systemctl enable haveged.service
- Once that is done, you can start Tomcat and enable it to start on reboot with the following commands:
sudo systemctl start tomcat.service
sudo systemctl enable tomcat.service
Configuring Apache Tomcat
- Now that Tomcat has been installed, you will need to configure the firewall to allow browser access using the following commands:
sudo firewall-cmd --zone=public --permanent --add-port=8080/tcp
sudo firewall-cmd --reload
- In order to start using the Tomcat Graphical User Interface (GUI), you will need to configure the users file with a new username and password. In this example, replace newusername and newpassword with the username and password you want to use to log in to Tomcat.
sudo nano /opt/tomcat/conf/tomcat-users.xml
Within:</tomcat-users ...>...</tomcat-users>
Insert:<user username="newusername" password="newpassword" roles="manager-gui,admin-gui"/>
- Restart Tomcat
sudo systemctl restart tomcat.service
Testing Apache Tomcat
To test your Tomcat installation, you can simply visit your server IP followed by :8080. If the installation was successful, you should immediately see the login page.
Experience unrestricted processing power on state-of-the-art hardware and your preferred operating system with Bare Metal Hosting!
Ubuntu, Debian, OpenSUSE, or Load your own OS Unmanaged Hosting Perfect for SysAdmins Dedicated Resources
Ho to remove the 8080 from the url?
I found some posts via online search, where they discuss using port 443 with an SSL, or using a proxy.