Tomcat is developed by Apache Foundations. Apache Tomcat is an open-source web server for a Java-based web application. Tomcat is licensed under Apache License version 2. Apache Tomcat team has announced its latest Tomcat 9.0.31 release on Feb 5, 2020. This article will help you to install Tomcat 9 on CentOS, Red Hat and Fedora systems. To install other version of tomcat visit Tomcat 8 on CentOS & Red Hat.
Step 1 – Prerequsities
Tomcat 9 is designed to run on Java SE 8 and later. So make sure you have installed the correct version on your system.
java -versionjava version "11.0.2" 2019-01-15 LTS Java(TM) SE Runtime Environment 18.9 (build 11.0.2+9-LTS) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+9-LTS, mixed mode)
If you don’t have Java installed on your system or installed lower version, use the following link to install Java first.
Step 2 – Download Tomcat Archive
Download Apache Tomcat 9 archive file using following commands or you can visit Tomcat 9 official download page for download most recent available version. After downloading extract archive file in /usr/local directory. You may change this location as per your setup.
wget wget http://www-us.apache.org/dist/tomcat/tomcat-9/v9.0.31/bin/apache-tomcat-9.0.31.tar.gz tar xzf apache-tomcat-9.0.31.tar.gz sudo mv apache-tomcat-9.0.31 /usr/local/tomcat9
Step 3 – Set Environment Variables
Let’s configure the CATALINA_HOME environment variable in your system using the following commands. It is required to run the Tomcat server.
echo "export CATALINA_HOME="/usr/local/tomcat9"" >> ~/.bashrc source ~/.bashrc
Step 4 – 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.
vim /usr/local/tomcat9/conf/tomcat-users.xml <!-- 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 5 – Start Tomcat Service
Tomcat is very easy to use, There is no need to compile its source. You simply extract the archive and start the tomcat server. Tomcat by default start on port 8080, So make sure no other application using the same port.
cd /usr/local/tomcat9 ./bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat9 Using CATALINA_HOME: /usr/local/tomcat9 Using CATALINA_TMPDIR: /usr/local/tomcat9/temp Using CLASSPATH: /usr/local/tomcat9/bin/bootstrap.jar:/usr/local/tomcat9/bin/tomcat-juli.jar Tomcat started.
Step 6 – Access Tomcat in Browser
Tomcat server default works on port 8080. Access tomcat on a web browser by connecting your server on port 8080.