The following article shows how to install Tomcat v9.0.xx on CentOS Linux 7.x.xxxx.
Open SSH session as root, to your Centos box and check if Java is installed on your system:
If it’s not, check which version is available, execute the following command and look for SDK package ending with .x86_64
yum search java | grep -i JDK
As of today, the most recent one appears to be: java-1.8.0-openjdk.x86_64
So that’s the one (along with OpenJDK-devel) we’ll install using this command:
yum install java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-devel.x86_64
Now, open your browser and navigate to http://archive.apache.org/dist/tomcat/
Browsing above URL I found that the most recent package available is following:
So let’s download it and untar it:
tar zxvf apache-tomcat-9.0.0.M9.tar.gz
Note: At this point, if you want, you can navigate to /usr/share/ and you can delete apache-tomcat-9.0.0.M9.tar.gz, you don’t need it anymore.
Now, let’s add user ‘tomcat’ to CentOS, because we don’t want to use root account when running Tomcat (that could be a security issue):
useradd -g tomcat -s /bin/bash -d /usr/share/apache-tomcat-9.0.0.M9 tomcat
chown -Rf tomcat.tomcat /usr/share/apache-tomcat-9.0.0.M9/
Let’s switch from ‘Root’ over to ‘Tomcat’ user:
su – tomcat
And let’s start Tomcat 8.0.24 we’ve just installed:
At this point, your Tomcat server should be running on port 8080, so open browser and let’s see if it’s running.
Go to http://YourServerDomain:8080, it’ll look something like this:
Troubleshooting: If the page doesn’t load, it’s possible your CentOS 7 / RHEL 7 system has enabled FirewallD and you need to create a permanent exception for port 8080:
firewall-cmd --add-port=8080/tcp --permanent
You can optionally do the same thing using the following command:
firewall-cmd --add-service=http --permanent
Now restart FirewallD service and see if the page loads.
systemctl restart firewalld
Ok, it’s working, but at this point, you still won’t be able to log into it. So let’s shut down the server:
And open the following file in your text editor of choice:
Scroll down to the roles section, entire section will be commented out, so first make sure it’s uncommented. Then setup two users, as following (except make sure you use your own passwords):
<role rolename="manager-gui" />
<user username="manager" password="YOUR_PASSWORD" roles="manager-gui" />
<role rolename="admin-gui" />
<user username="admin" password="YOUR_PASSWORD" roles="manager-gui,admin-gui" />
Above sets up user manager and user admin, idea is that manager can access only manager section, while the admin can access manager and admin section (both).
Save the change and now you can start Tomcat again:
Now you can log in to your newly installed Tomcat with admin/yourpassword credentials, which we’ve setup earlier in tomcat-users.xml file.
How long did it take? 2-3 minutes? :)
To close this topic, I’ve created a short video for those who want to follow the similar instructions to install Tomcat 8: