fbpx

1. Deploy a WAR File on a Linux Server with Tomcat – Clear Solution

Table of Contents

1. Deploy a WAR File on a Linux

Introduction: Deploy a WAR File on a Linux

Are you looking to seamlessly deploy a war file on a Linux server using Tomcat? Understanding the process of deploying a WAR (Web Application Archive) file is essential for any developer or system administrator. In this comprehensive guide, we’ll walk you through each step of deploying a WAR file on a Linux server running Tomcat, simplifying what might seem like a complex process.

What You Will Learn:

  • Preparation: Ensuring your environment is ready for deployment.
  • Uploading the WAR File: Transferring your application to the server.
  • Deploying on Tomcat: Placing your application within Tomcat’s environment.
  • Testing and Troubleshooting: Ensuring a successful deployment

Prerequisites: For Deploy a WAR File on a Linux

  • deploying a WAR file on a LinuxLinux server with Tomcat, JDK & MySQL Server installed.
  • WAR file of the web application you want to deploy.
  • Putty Software (windows)
  • WinSCP Software (windows)

Putty

Putty is a versatile software primarily used for remote access to systems via various network protocols, such as SSH, and Telnet.

WinSCP (Windows Secure Copy): –

It is a popular open-source SFTP, SCP, and FTP client for Windows. It allows users to transfer files between a local and remote computer securely.

Install This requirement on the Linux server:

Step 1:  How to install JDK in the Linux server.

First, check whether JDK is installed or not

Command  :- java –version

If JDK is not installed on the Linux server then install it.

Command :- sudo yum install  java-1.8.0-openjdk.x86_64

deploying a WAR file on a Linux 1
deploying a WAR file on a Linux 1

After successfully installing JDK, now check the JDK version and its path.

Command: -java -version (for version)

deploying a WAR file on a Linux

Command:  whereis java  ( for installation path)

Deploying A WAR File On A Linux 3

Step 2:  How to install Apache Tomcat on a Linux server

  • First, check whether Tomcat is installed or not

Command:- tomcat  or whereis tomcat

If Tomcat is not installed in the Linux server then install it using the following command

Command:- sudo yum install tomcat

Deploying A WAR File On A Linux

Press Y to continue.

Deploying A WAR File On A Linux

To locate the Tomcat directory and the web apps folder after a successful installation
  • To find the Tomcat directory, use the command ‘whereis‘ tomcat’ in your terminal.
  • Navigate to the Tomcat directory using ‘cd /usr/share/tomcat‘.
  • List the contents of the directory with ‘ls’.
  • List the contents of the ‘web apps’ folder using ‘ls’ to view the deployed web applications.”

Command:- whereis tomcat

Deploying A WAR File On A Linux

Deploying A WAR File On A Linux

After successfully installing Tomcat, you can check the Tomcat version by following these steps:
  • Hit Command: tomcat
  • Navigate to the Tomcat directory: Command: cd /usr/sbin/
  • Check the Tomcat version using the command: tomcat version

Deploying A WAR File On A Linux

Step 3: How to Install MySQL Server on a Linux System

MySQL is a widely used open-source relational database management system. Installing it on a Linux server involves a few straightforward steps. Here’s a step-by-step guide:

1. Checking if MySQL is Already Installed

Before proceeding with the installation, it’s a good idea to check if MySQL is already installed on your system. You can use the whereis command to do this:

Command :- whereis mysql

Deploying A WAR File On A Linux

2. If  Not Then Install  MySQL Server on a Linux System

If the MySQL server isn’t already installed on your Linux server, you can proceed by using the appropriate package manager command for your system.

Command:-   sudo yum install mysql-server

Deploying A WAR File On A Linux

After a successful installation, it’s crucial to immediately change the MySQL server’s root password for enhanced security. This can be accomplished using the following command:

3. Stopping the MySQL Server: Distribution-Specific Commands

Command:-  service mysqld stop

4. Restarting the MySQL Server with the –skip-grant-tables Option

Command:- mysqld_safe –skip-grant-tables

5. Log into MySQL using the following command:

Command:- mysql

6. Resetting the MySQL Server Password

Command:-

  • UPDATE mysql.user SET Password=PASSWORD(‘NEW-PASSWORD’) WHERE User=’root’;
  • FLUSH PRIVILEGES;
  • exit;
7. Stopping the MySQL Server and Prompting for a New Root Password

Command:- mysql admin -u root -p shutdown

8. Starting the MySQL Server: Distribution-Specific Commands

Command:- service mysqld start

9. Logging into MySQL Server with the Updated Password

Command:-  mysql -u root -p

Enter your new password _

Deploying A WAR File On A Linux

10. Creating Schemas and Tables in MySQL

After logging into the MySQL server with the updated password, you can create new schemas and tables for organizing your data.

11. To check existing databases (schemas), use the following command:

Command: show databases;

Deploying A WAR File On A Linux

12. To create a new database (schema), you can use the following command:

Deploying A WAR File On A Linux

13. Now create Table

Deploying A WAR File On A Linux

Step 4: How to Create War File of Web Application

  1. Open your project in Eclipse or your preferred IDE.
  2. Right-click on the project.
  3. Choose “Export” > “WAR file”.
  4. Select the project and destination.
  5. Click “Finish” to export as a WAR file.

Deploying A WAR File On A Linux

Step 5: Deploying A WAR File On A Linux Apache Tomcat

  1. Using the Manager App (webapp):
    • Access the Tomcat Manager App by navigating to http://localhost:8080/manager/html.
    • Log in with appropriate credentials (configured in tomcat-users.xml).
    • Use the Manager App’s interface to the WAR file by uploading it from your local machine.
  2. Using WinSCP Software:
    • Use WinSCP to securely transfer the WAR file from your local machine to the server where Tomcat is hosted.
    • Access the Tomcat server directory (webapps) via WinSCP.
    • Copy and paste the WAR file into the webapps directory of Tomcat.
      Deploying A WAR File On A Linux When you successfully log in, a new window will open, displaying…Deploying A WAR File On A Linux Navigate to the webapps folder in the Linux system: /usr/share/tomcat/webapps/

Deploying A WAR File On A Linux

“Now, simply drag and drop the WAR file from your local system to the ‘webapps‘ folder in the Linux system. Afterward, either restart the Tomcat service or refresh it for the changes to take effect.”

Deploying A WAR File On A Linux

Read More Answer…

At our Java by Kiran Academy, based in Pune, we offer wide range of IT courses, including Java, python course in pune, .NET, testing classes in pune, MEAN, MERN, and more. Enroll now for the flexibility of attending classes either offline or online.

 

Read Quara’s Answer…

Read More Posts Like This…

Our Campus Drive

Subscribe to Us on YouTube

Get daily updates on:
  • Technical
  • Interview 
  • Upcoming Campus 
  • Job-Related Fairs

Are you looking for a better job?
Talk to our Career Expert Now !


Recommended Videos

Grab This Offer

Request a Callback

For any Queries? Talk to our Experts
+918888809416

Available 24x7 to answer your queries

Grab This Offer Soon

Register Now