A Comprehensive Guide to Deploying a Web Application on Tomcat
This article outlines the complete process of deploying a web application, specifically a ROOT.war
file, onto a Tomcat server. The instructions account for common hurdles, such as file transfer and permission issues, and provide all the necessary commands and explanations.
1. Transferring the ROOT.war
File
The deployment begins with transferring the ROOT.war
file from the jump host to the application server. This is done using the scp
command. We'll first copy the file to a temporary location on the application server to avoid initial permission issues.
From the jump host, execute this command:
scp /tmp/ROOT.war <username>@<application_server_ip>:/tmp/
-
/tmp/ROOT.war
: The source file on the jump host. -
<username>@<application_server_ip>
: The destination user and server address. -
:/tmp/
: The temporary directory on the application server where the file will be placed.
2. Resolving Permissions and Moving the File
Once the file is on the application server, you must move it to Tomcat's webapps
directory. The webapps
directory is typically owned by the tomcat
user for security, which means a regular user like steve
won't have permission to write to it. To solve this, you'll temporarily change the ownership of the directory.
First, log in to the application server:
ssh <username>@<application_server_ip>
Next, change the ownership of the webapps
directory. The exact path may vary, but for a yum
installation, it's usually /var/lib/tomcat/webapps/
.
sudo chown <username>:<username> /var/lib/tomcat/webapps/
Now, move the ROOT.war
file from the temporary directory to the webapps
directory:
sudo mv /tmp/ROOT.war /var/lib/tomcat/webapps/
Finally, for security, it is a best practice to revert the ownership of the webapps
directory back to the tomcat
user.
sudo chown tomcat:tomcat /var/lib/tomcat/webapps/
3. Configuring the Tomcat Server
If you installed Tomcat via a package manager, its port might be set to the default 8080
. To run the application on port 3003
, you need to edit the server.xml
configuration file.
-
Locate the
server.xml
file: This is typically at/etc/tomcat/server.xml
or/usr/share/tomcat/conf/server.xml
. -
Edit the file using a text editor like
vi
:
sudo vi /etc/tomcat/server.xml
- Find the
<Connector>
tag and change the port from8080
to3003
:
<Connector port="3003" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
- Save and exit the file.
4. Starting the Tomcat Service and Verification
After moving the ROOT.war
file and configuring the port, you must restart the Tomcat service for the changes to take effect. Tomcat will automatically detect and deploy the ROOT.war
file upon startup.
Restart the Tomcat service:
sudo systemctl restart tomcat
Verify the deployment using curl
from either the jump host or a local terminal. A successful deployment will return the HTML content of your web application.
curl http://stapp02:3003
This command should display the content of your web application, confirming that the deployment was successful and the application is running correctly on the specified port.
Top comments (0)