Apache Tomcat Installation on Linux
Introduction
Apache Tomcat is an open-source, lightweight web server for running Java-based websites and applications. It's an implementation of the Jakarta EE platform which is the modification of the Java EE platform to accommodate distributed computing and web services. This article explains how to install Apache Tomcat on Alpine Linux or Ubuntu.
Prerequisites
1 . Need Linux server on cloud or vm
2 . Create a non root user with sudo access.
Installation of Java in Ubuntu
sudo apt update
sudo apt install default-jdk -y
java --version
Installation of Java in Alpine Linux
apk update
apk add openjdk11
java --version
Installation of Apache Tomcat
Visit on official website of Tomcat webserver.
-
Download Tar file
Create folder and save zipped file on folder. Use wget command to dowload tar file.
wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.0.27/bin/apache-tomcat-10.0.27.tar.gz
unzip file by using command tar zxvf zippedfile.tar.gz
Change execution policy for both file
$ chmod +x startup.sh
$ chmod +x shutdown.sh
- Edit files because the tomcat application don't allow you to login from the browser. changing a default parameter in context.xml does address this issue
/home/tomcat/apache-tomcat-10.0.27/webapps/host-manager/META-INF
In my directory path can be different change it according to your files directory.
make this changes on context file and save
Repeat this step but on another file.
/home/tomcat/apache-tomcat-10.0.27/webapps/manager/META-INF
- After Edit both file make change on role based access file conf/tomcat-user.xml
# Copy and paste on tomcat-user.xml
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="admin" password="admin" roles="manager-gui, manager- script, manager-jmx, manager-status"/>
<user username="deployer" password="deployer" roles="manager-script"/>
<user username="tomcat" password="s3cret" roles="manager-gui"/>
- save file with command of "Escape + :wq " vim command.
Start Server
execute startup.sh file /bin/startup.sh
Go to localhost:8080
Shutdown server
shutdown server by execute bin/shutdown.sh
Portchange
Default port is opened 8080 you can change it to any port.
Using unique ports for each application is a best practice in an environment. But tomcat and Jenkins runs on ports number 8080. Hence lets change tomcat port number to 8090. Change port number in conf/server.xml file under tomcat home
Deploy
- Deploy war file /webapps/