Apache Tomcat is a web server environment for running programs written in the Java programming language. It can serve dynamically generated sites with Servlet and JSP. Tomcat is one of the most popular choices for Java application server deployments. Below we’ll cover how to manage Tomcat on Control Web Panel (CWP).
- Install Tomcat on CWP
- Access Tomcat Applications
Install Tomcat on CWP
Follow these steps to install Apache Tomcat.
- Log into CWP as an administrator.
- On the left, search for and select Tomcat Manager.
- Select a Tomcat version to install from the dropdown menu, then Install now. Select Continue in the pop-up window. This will also install the CWP Tomcat engine.
- Upon refresh, you’ll see the Tomcat server status, port number, and version number. To the right you’ll see that OpenJDK was installed. This is the open-source Java installation with Font Renderer and the latest features. For another OpenJDK version, or the proprietary Oracle JRE/JDK, follow our guide on how to install Java on CentOS.
- You should now be able to type “youservername:8080” into your web browser and view the Apache Tomcat default page. If not, ensure that port 8080 is open in your CWP server firewall and try again.
Tomcat in User Panels
If you want to allow regular users to manage Tomcat apps:
- Select the Configurations tab at the top of the Tomcat management section.
- Check the box for Tomcat server available in user panel. You can enable access for all accounts or specific ones.
- Once you’ve made your decision, select Save user panel options. Now, CWP end users can access Tomcat apps from Domains > Tomcat Manager. Users currently logged in may need to refresh their browser page to see the new section.
During our testing, Tomcat Manager did not display in user panels. If you experience similar issues, contact the CWP team directly.
Harden Apache Tomcat Server Security
On the default Apache Tomcat version 10.0.16 page you’ll see an important notice:
“For security, access to the manager webapp is restricted. Users are defined in: $CATALINA_HOME/conf/tomcat-users.xml”
You can edit this file in the CWP terminal or Tomcat Manager.
Due to an unknown error, we were unable to use the Tomcat Manager to quickly make these changes. We will cover how to attempt this method on your CWP server and bypass the issue if required.
- In CWP Tomcat Manager, click on the Configuration tab.
- Under “TomCat server configuration files,” select tomcat-users.xml from the drop-down menu. The XML file will load at the bottom of the page.
- Without making any changes, select Save file. If a notification in the upper-right corner states “Success,” this means you’re able to edit the file in the graphical interface. Continue to step 4.
If an error shows in the upper-right corner stating “Invalid configuration file,” you’ll need to make changes from the terminal emulator. Note the file path to your tomcat-users.xml file. It should resemble “/usr/local/tomcat/tomcat10/conf/tomcat-users.xml.”
At the top, select Terminal > Simple Terminal. Or you can log into your CWP server via SSH.
Edit the file with a text editor:
- On or near line 36 you’ll see two “user username” lines encapsulated between two comment lines (“<!–” and “–>”):
<user username="admin" password="<must-be-changed>" roles="manager-gui"/>
<user username="robot" password="<must-be-changed>" roles="manager-script"/>
Remove the comment lines.
- Add “admin-gui” to the admin line as shown below, and update the passwords (and “admin” username to something else if desired).
<user username="admin" password="StrongPasswrd1" roles="manager-gui,admin-gui"/>
<user username="robot" password="StrongPasswrd2" roles="manager-script"/>
- Add more users to the Tomcat configuration file if necessary, using the same format. You may notice a “tomcat_cwpuser” at the bottom of the file. This is used by CWP to integrate Tomcat with CWP.
- If editing the file in Tomcat Manager, select Save file & reload server at the top. If editing the file in the terminal, save changes.Then return to the CWP Tomcat Manager dashboard tab and select Restart server.
- You should now be able to log into your Tomcat hosting panel with your new admin credentials at “yourserverhostname:8080/host-manager.”
Access Tomcat Applications
The Applications tab is where you can deploy and manage Tomcat applications. Installed with the Tomcat server are:
- Servlet and JSP Examples (/examples)
- Tomcat Documentation (/docs)
- Tomcat Host Manager Application (/host-manager)
- Tomcat Manager Application (/manager)
- Welcome to Tomcat (/)
The table shows applications’ file path, assigned user, status, and number of sessions running. The action buttons allow you to edit, stop, reload, delete, and expire sessions for an app.
Deploy a Tomcat Application
Follow these steps to deploy Tomcat applications as an admin user.
- From the “Applications” tab, select Deploy application at the top.
- Assign a CWP user. Add a user if necessary.
- Select a domain or subdomain.
- Specify a context path.
- Select a deployment from the drop-down list (WAR file, XML configuration file, or directory).
- Select the necessary file or directory.
- Select Save.
Learn about more ways to manage your Control Web Panel server.