Apache Tomcat is a widely used open-source Java Servlet Container developed by the Apache Software Foundation (ASF). Tomcat acts as a web server for Java-based web applications and is an essential tool for developers working with Java Servlets and JavaServer Pages (JSPs). This guide will take you through the process of installing Tomcat 11 on Ubuntu, Debian, and Linux Mint systems.
Warning:
Please be aware that as of the writing of this guide, Apache Tomcat 11 is currently in an Alpha release stage. This version is considered unstable and is not suitable for production environments. If you are looking for a stable version of Tomcat for production use, please consider installing Tomcat 9 or Tomcat 10 with following links:
Prerequisites
Before starting the installation, ensure that you have:
- A system running Ubuntu, Debian, or Linux Mint.
- Sudo privileges or access to the root user.
- Java Development Kit (JDK) installed on your system. Tomcat 11 requires JDK 8 or later.
Step 1: Install Java Development Kit (JDK)
Tomcat 11 requires Java to run. If you do not have Java installed, you can install the default JDK package from your distribution’s repository.
- On Ubuntu and Linux Mint:
sudo apt update
sudo apt install default-jdk
- On Debian:
Debian users might need to enable the non-free repository to install the default JDK package. Once enabled, run the same commands as above.
Step 2: Download Tomcat 11
You can download the latest version of Tomcat 11 using the wget command. As of writing this guide, the latest version is 11.0.0-M17, but you should check the official Tomcat website for any newer versions.
Run the following command to download Tomcat 11:
wget https://dlcdn.apache.org/tomcat/tomcat-11/v11.0.0-M17/bin/apache-tomcat-11.0.0-M17.tar.gz
Step 3: Install Tomcat 11
After downloading, you need to extract the Tomcat archive and move it to a suitable location.
- Extract the archive:
tar -xvzf apache-tomcat-11.0.0-M17.tar.gz
- Move the extracted folder to /opt (or any location of your choice):
sudo mv apache-tomcat-11.0.0-M17 /opt/tomcat11
Step 4: Create a Tomcat System User
For security reasons, Tomcat should not run as the root user. Create a new user and group that will run the Tomcat service.
sudo groupadd tomcat
sudo useradd -s /bin/false -g tomcat -d /opt/tomcat11 tomcat
Step 5: Update Permissions
Change the ownership of the Tomcat directory to the user and group we just created.
sudo chown -R tomcat:tomcat /opt/tomcat11
Step 6: Create a systemd Service File
To manage Tomcat as a service, create a systemd service file.
- Open a new file in /etc/systemd/system with your favorite text editor, for example:
sudo nano /etc/systemd/system/tomcat.service
- Add the following content to the file:
[Unit] Description=Tomcat 11 servlet container After=network.target [Service] Type=forking User=tomcat Group=tomcat Environment="JAVA_HOME=/usr/lib/jvm/default-java" Environment="CATALINA_PID=/opt/tomcat11/temp/tomcat.pid" Environment="CATALINA_HOME=/opt/tomcat11" Environment="CATALINA_BASE=/opt/tomcat11" ExecStart=/opt/tomcat11/bin/startup.sh ExecStop=/opt/tomcat11/bin/shutdown.sh RestartSec=10 Restart=always [Install] WantedBy=multi-user.target
- Reload the systemd daemon to apply the changes:
sudo systemctl daemon-reload
- Enable and start the Tomcat service:
sudo systemctl enable tomcat
sudo systemctl start tomcat
Step 7: Setup Tomcat Web Interface Login
To manage your Tomcat server via the web interface, you need to create user roles and a user with login permissions. This configuration is done in the tomcat-users.xml file.
- Open the tomcat-users.xml file located in /opt/tomcat11/conf/:
sudo nano /opt/tomcat11/conf/tomcat-users.xml
- Add user roles and a user between the <tomcat-users> tags. Replace username and password with your desired admin username and password:
<tomcat-users> <!-- existing user roles and users --> <role rolename="manager-gui"/> <role rolename="admin-gui"/> <user username="admin" password="password" roles="manager-gui,admin-gui"/> </tomcat-users>
This configuration provides the admin user with access to the web interface for management (manager-gui) and administrative (admin-gui) tasks.
Step 8: Allow Remote Access to Tomcat Web Interface
By default, the Tomcat server is configured to allow access to the web interface only from the local machine. To enable access from other machines on your network, you need to modify the configuration for the Manager and Host Manager applications.
- Open the context.xml file located under both the manager/META-INF/ and host-manager/META-INF/ directories in your Tomcat installation:
sudo nano /opt/tomcat11/webapps/manager/META-INF/context.xml
sudo nano /opt/tomcat11/webapps/host-manager/META-INF/context.xml
- In each file, comment out or remove the IP address restriction found within the <Context> tag. It looks similar to this:
<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
Removing or commenting out this line will remove the restriction, allowing network users to access the Tomcat web interface.
- Save and close both files. Restart Tomcat to apply the changes:
sudo systemctl restart tomcat
After completing these steps, you should be able to log into the Tomcat web interface using the username and password you specified in tomcat-users.xml. Remember, allowing remote access to your Tomcat web interface can pose a security risk. Ensure that your network is secure and consider implementing additional security measures such as firewalls and VPNs to protect your Tomcat server.
Step 9: Verify Installation
After starting Tomcat, you can verify that it’s running by accessing the default Tomcat page. Open your web browser and visit http://your_server_ip:8080.
You should see the Tomcat welcome page, indicating that Tomcat is installed and running correctly.
Conclusion
Congratulations! You have successfully installed Apache Tomcat 11 on your Ubuntu, Debian, or Linux Mint system. You can now deploy your Java web applications and use Tomcat as your web server. For further configuration and deployment options, refer to the official Tomcat documentation.
6 Comments
so great.
This is an amazing guide. I found others which where just confusing and didn’t achieve the objective. Thank you so much!
Thanks.
I don’t know the servername. Where did you get it from?
Thank you so much !
Thank you so much