This tutorial shows you how to install Tomcat 8.5 on CentOS 7. Tomcat is an open source implementation of the Java Servlet, JavaServer Pages, Java Expression Language and Java WebSocket technologies.
Before starting with this tutorial, make sure you are logged into your server with a user account with sudo privileges or with the root user. It is best practice to run administrative commands as sudo user instead of root, if you don¡¯t have a sudo user on your system you can create one by following these instructions.
Tomcat 8.5 requires Java SE 7 or later. In this tutorial we will install OpenJDK, the open source implementation of the Java Platform which is the default Java development and runtime in CentOS 7.
The installation is simple and straight forward:
sudo yum install java-1.8.0-openjdk-devel
Copy
If you want to install Oracle Java instead of OpenJDK please check this guide.
Running Tomcat as a root user is a security risk and is not recommended. Instead we will create a new system user and group with home directory /opt/tomcat that will run the Tomcat service:
We will download the latest version of Tomcat 8.5.x from the Tomcat downloads page. At the time of writing, the latest version is 8.5.33. Before continuing with the next step you should check the download page for any new version.
Change to the /tmp directory and use wget to download the zip file:
cd /tmpwget http://www-us.apache.org/dist/tomcat/tomcat-8/v8.5.33/bin/apache-tomcat-8.5.33.zip
Copy
Once the download is completed, extract the zip file and move it to the /opt/tomcat directory:
Because Tomcat 8.5 is updated frequently to have more control over versions and updates, we will create a symbolic link latest which will point to the Tomcat installation directory:
The tomcat user that we previously set up needs to have access to the tomcat directory, so we will change the directory ownership to user and group tomcat:
sudo chown -R tomcat: /opt/tomcat
Copy
and we will also make the scripts inside bin directory executable:
If your server is protected by a firewall and you want to access the tomcat interface from the outside of the local network you also need to open port 8080.
Use the following commands to open the necessary port:
In most cases, when running Tomcat in a production environment you will use a load balancer or reverse proxy and it¡¯s a best practice to allow access to port 8080 only to your internal network.
At this point Tomcat is installed and we can access it with a web browser on port 8080, but we can not access the web management interface because we have not created a user yet.
Tomcat users and their roles are defined in the tomcat-users.xml file.
If you open the file you will notice that it is filled with comments and examples describing how to configure the file.
sudo vim /opt/tomcat/latest/conf/tomcat-users.xml
Copy
To add a new user who will be able to access the tomcat web interface (manager-gui and admin-gui) we need to define the user in tomcat-users.xml file as shown bellow. Make sure you change the username and password to something more secure:
By default Tomcat web management interface is configured to allow access only from the localhost. If you want to be able to access the web interface from a remote IP or from anywhere which is not recommended because it is a security risk you can open the following files and make the following changes.
If you need to access the web interface from anywhere open the following files and comment or remove the lines highlighted in yellow:
If you need to access the web interface only from a specific IP, instead of commenting the blocks add your public IP to the list. Let¡¯s say your public IP is 41.41.41.41 and you want to allow access only from that IP:
Open your browser and type: http://<your_domain_or_IP_address>:8080
Upon successful installation, a screen similar to the following will appear:
Tomcat web application manager dashboard is available at http://<your_domain_or_IP_address>:8080/manager/html. From here you can deploy, undeploy, start, stop and reload your applications.
Tomcat virtual host manager dashboard is available at http://<your_domain_or_IP_address>:8080/host-manager/html. From here you can create, delete and manage Tomcat virtual hosts.
You have successfully installed Tomcat 8.5 on your CentOS 7 system and learned how to access the Tomcat management interface. You can now visit the official Apache Tomcat 8 Documentation and learn more about the Apache Tomcat features.
If you hit a problem or have a feedback, leave a comment below.