Apache Tomcat is an open-source, lightweight web server designed for hosting Java websites and applications. This article outlines the process of installing Apache Tomcat on an Ubuntu 20.04 cloud server.
Update the operating system and install the Java Runtime Environment.
$ sudo apt update
$ sudo apt install default-jdk -y
Verify the installed version of Java.
$ java -version
Download the latest version of Apache Tomcat, then extract and proceed with configuration and installation. We'll use version 10.0.8 as an example.
$ wget https://archive.apache.org/dist/tomcat/tomcat-10/v10.0.8/bin/apache-tomcat-10.0.8.tar.gz
$ sudo tar xzvf apache-tomcat-10.0.8.tar.gz
$ sudo mkdir /opt/tomcat/
$ sudo mv apache-tomcat-10.0.8/* /opt/tomcat/
$ sudo chown -R www-data:www-data /opt/tomcat/
$ sudo chmod -R 755 /opt/tomcat/
Edit the Apache Tomcat user configuration file to set up administrator and manager accounts.
$ sudo nano /opt/tomcat/conf/tomcat-users.xml
Add the following code under the
<!-- user manager can access only manager section -->
<role rolename="manager-gui" />
<user username="manager" password="StrongPassword" roles="manager-gui" />
<!-- user admin can access manager and admin section both -->
<role rolename="admin-gui" />
<user username="admin" password="StrongPassword" roles="manager-gui,admin-gui" />
For convenience, we set up a Systemd service for Apache Tomcat.
$ sudo nano /etc/systemd/system/tomcat.service
The content is as follows:
[Unit]
Description=Tomcat
After=network.target
[Service]
Type=forking
User=root
Group=root
Environment="JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"
Environment="CATALINA_BASE=/opt/tomcat"
Environment="CATALINA_HOME=/opt/tomcat"
Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
[Install]
WantedBy=multi-user.target
Reload the systemd daemon service to apply changes.
$ sudo systemctl daemon-reload
$ sudo systemctl start tomcat
$ sudo systemctl enable tomcat
Finally, visit http://[your-server-IP]:8080. If everything is set up correctly, you should see the default homepage of Apache Tomcat. With Apache Tomcat now installed, you can begin deploying web applications.
23-02-2024 02:02:07
22-02-2024 03:19:32
22-02-2024 03:16:03
22-02-2024 03:14:03
22-02-2024 03:11:58