The Apache Software Foundation, also known as ASF recently released Apache Tomcat server 9 on December 8, 2016. Tomcat server implements Java servlet and Java servlet technologies like JSP Java WebSocket. Apache Tomcat is an open-source web server and servlet container that is used to serve Java applications.
It is developed by the Apache Software Foundation, written in Java and released under Apache License 2.0.
In this article, we will guide you through the steps of installing Apache Tomcat 9 on a CentOS 7 VPS. Apache Tomcat is the most popular and widely used Java application server. It is an open source web server and servlet container developed by the Apache Software Foundation. It executes Java servlets and renders Web pages that include Java Server Page coding. Tomcat has been downloaded more than 10 millions times and it powers mission-critical sites like WalMart, The Weather Channel and much more. Installing Apache Tomcat 9 on CentOS 7 is a fairly easy task, and it shouldn’t take more than 10 minutes for Tomcat 9 to be installed on your CentOS 7 based virtual server.
Apache Tomcat 9 is built on top of the latest Java EE 8 specifications such as Servlet 4.0, EL 3.1, JSP 2.4 and WebSocket 1.2. Also, it has a lot of bug and security fixed and major improvements such as the following:
- implements HTTP/2 (requires the APR/native library)
- supports TLS virtual hosting
- Allows OpenSSL performance with NIO/NIO2 APIs
- using OpenSSL for TLS with the JSSE connectors
- SNI and multiple certificates supported by all connectors
- OpenSSL engine option for NIO and NIO2
and much more…
Login and update the system
Login to your CentOS 7 VPS via SSH as user root
ssh root@IP_Address -p7022
and make sure that all installed packages are up to date
yum -y update
Install Java 8
Apache Tomcat 9 requires Java 8 or newer to be installed on the server. Java 8 packages are available in the default CentOS 7 repositories. Run the following command to install Java 8
yum install java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-devel.x86_64
This will install Java 8 and all its dependencies. Once the installation is completed, you can check the installed version using the following command
You should get the following output:
openjdk version "1.8.0_161"
OpenJDK Runtime Environment (build 1.8.0_161-b14)
OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)
Install Tomcat 9
Go to the official Apache Tomcat website and download the most recent version of the software to your server. At the moment the most recent release is version 9.0.11.
unpack the downloaded zip archive
unzip apache-tomcat-9.0.7.zip -d /opt
This will create a new directory named ‘apache-tomcat-9.0.11’. We will rename it to something simpler
mv apache-tomcat-9.0.11/ tomcat
Run the following commands to set the CATALINA_HOME environment variable
echo "export CATALINA_HOME='/opt/tomcat/'" >> ~/.bashrc
It is not recommended to run Apache Tomcat as user root, so we will create a new system user which will run the Tomcat server
useradd -r tomcat --shell /bin/false
and change the ownership of all Tomcat files
chown -R tomcat:tomcat /opt/tomcat/
We recommend you to run a short testing on Tomcat to make sure that there is no error and it is installed successfully so follow the below-given process.
Run below given command :
cd /opt/tomcat/bin/ ./startup.sh
Currently, Tomcat is using port number 8080 so check the open port using netstat command as shown:
You can check this using a web browser with http://yourserver_IP:8080 then you’ll see the homepage of Apache Tomcat Server but we recommend you to use browser later at final testing because we will run Tomcat with a system service file in the final configuration.
Now run following commands :
cd /opt/tomcat/bin/./shutdown.shchown -hR tomcat:tomcat /opt/tomcat/
Creating a system Service File
Now you’ll need to create a system service file to run Apache Tomcat as a tomcat user. Creation of a system service file is recommended for easy starting and stopping the service.
Run following command :
Add the content below into nano text editor, you can simply copy/paste this into the file:
Description=Apache Tomcat 8 Servlet Container
Save and close the file then run the following commands to start the Tomcat service and enable Tomcat service to start on boot:
systemctl daemon-reload systemctl start tomcat systemctl enable tomcat
Once again check for the open port using netstat command shown below:
Now run the command below and make sure that service is active as shown below:
systemctl status tomcat
Create Tomcat 9 user account
You can create a new Tomcat user in order to be able to access the Tomcat manager. Open the tomcat-users.xml file and add the following lines:
<role rolename="admin-gui" />
<user username="admin" password="PASSWORD" roles="manager-gui,admin-gui"
Don’t forget to replace PASSWORD with an actual strong password.
By default, the Tomcat Manager is only accessible from a browser running on the same machine as Tomcat. If you want to remove this restriction, you’ll need to edit the Manager’s context.xml file, and comment out or remove the following line:
<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
Restart Apache Tomcat 9
restart the Apache Tomcat server for the changes to take effect.
systemctl restart tomcat
Tomcat 9 Web Access
Now, you will be able to access the Apache Tomcat Manager by clicking the ‘Manager App’ button on the homepage, or directly at http://IP_address:8080/manager/html using user ‘admin’ and password ‘PASSWORD’