Tomcat

Local Setup

# Switch to the root user and navigate to the /opt directory
sudo su; cd /opt

# Download the specified version of Apache Tomcat
sudo wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.98/bin/apache-tomcat-9.0.98.tar.gz

# Extract the downloaded Apache Tomcat archive
sudo tar -xvf apache-tomcat-9.0.98.tar.gz

# Navigate to the Tomcat configuration directory to modify the user credentials
cd /opt/apache-tomcat-9.0.98/conf

# Open the tomcat-users.xml file for editing to configure Tomcat users
sudo vi tomcat-users.xml
Add the following line before the closing tag in the tomcat-users.xml file
<user username="ibtisam" password="12345@s" roles="admin-gui,manager-gui,manager-script"/>
Modify the Manager web application's context.xml to disable IP restrictions

sudo vi /opt/apache-tomcat-9.0.98/webapps/manager/META-INF/context.xml
Comment out the RemoteAddrValve configuration by enclosing it in <!-- -->: - To "comment out" means adding the comment tags <!-- --> around a piece of code to disable it, preventing it from being executed or processed.

<!--
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
-->
Modify the Host Manager web application's context.xml to disable IP restrictions

sudo vi /opt/apache-tomcat-9.0.98/webapps/host-manager/META-INF/context.xml
Comment out the RemoteAddrValve configuration here as well:

<!--
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
-->

# Create symbolic links for the Tomcat startup and shutdown scripts for easier access
sudo ln -s /opt/apache-tomcat-9.0.98/bin/startup.sh /usr/bin/startTomcat
sudo ln -s /opt/apache-tomcat-9.0.98/bin/shutdown.sh /usr/bin/stopTomcat

# Start Tomcat using the custom command
sudo startTomcat

# Stop Tomcat using the custom command
sudo stopTomcat

# Check if Tomcat is running on port 8080
sudo netstat -tlnp | grep 8080
Key Notes:

  1. Tomcat Users:
  2. The <user> tag in tomcat-users.xml defines credentials for accessing the Tomcat Manager and Admin interfaces.

  3. IP Restrictions:

  4. By default, Tomcat restricts access to the Manager and Host Manager applications to localhost. Commenting out the RemoteAddrValve allows access from other IPs.

  5. Symbolic Links:

  6. The ln -s commands create shortcuts (startTomcat and stopTomcat) for easier execution of Tomcat's startup and shutdown scripts.

  7. Port Check:

  8. The netstat command verifies if Tomcat is running and listening on the default HTTP port (8080).