# Setup Tomcat server on Linux

1. Login to [Azure portal](https://portal.azure.com/)
    
2. Create a VM,
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695033485390/9e44155a-5dea-4d97-bbb8-c205b654aa79.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695033521197/35ef4eb7-f50c-43fe-a720-d3e443d3982a.png align="center")
    
3. After creating VM, add an inbound rule in VM's network port 8080.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695034158878/e109619e-992c-4981-b795-634552ebcd6c.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695034212816/d131b7d3-42fd-4b95-bae7-5dc4c4725d6f.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695034266124/84d69714-f96b-4e98-a12f-1cbcc37ee112.png align="center")
    
4. JDK & Tomcat server deployement,
    
    ```bash
    sudo apt-get update -y
    sudo apt install openjdk-11-jre -y #JDK installation
    cd /opt
    sudo wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.65/bin/apache-tomcat-9.0.65.tar.gz  #Will download the tomcat setup from the link
    sudo tar -xvf apache-tomcat-9.0.65.tar.gz  #extract from zip
    ```
    
    Now, we need to change the login credentials of tomcat. Follow the below steps,
    
    ```bash
    cd /opt/apache-tomcat-9.0.65/conf
    sudo vi tomcat-users.xml
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695145228784/76a9f3fb-d674-4141-b86a-ac12d89df018.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695145324136/8c3daca1-0e1b-4e3e-9a68-1a46e09a29a8.png align="center")
    
    Now we need to create links for the `startup.sh` and `shutdown.sh` to the path `/usr/bin/`.  
    Creating symbolic links to [`startup.sh`](http://startup.sh) in `/usr/bin` simplifies starting Tomcat from any directory, enhancing user convenience.
    
    ```bash
    sudo ln -s /opt/apache-tomcat-9.0.65/bin/startup.sh /usr/bin/starttomcat #This links will start the tomcat server
    sudo ln -s /opt/apache-tomcat-9.0.65/bin/shutdown.sh /usr/bin/stopTomcat  #This link will stop the tomcat server
    ```
    
    Now we need to comment-out few commands from the below locations. To comment-out, we need to start with `<!--` and end with `-->` ,
    
    ```bash
    sudo vi /opt/apache-tomcat-9.0.65/webapps/manager/META-INF/context.xml
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695146223380/668c6e57-9e9b-44e9-9fe6-0dca651d4b23.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695146258237/9b391561-5566-4076-a670-ddd12b15ba6d.png align="center")
    
    ```bash
    sudo vi /opt/apache-tomcat-9.0.65/webapps/host-manager/META-INF/context.xml
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695146482556/1366e422-13fa-4bc6-8a6f-ffded67f06c3.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695146500133/0d4cc110-3027-4ebc-94ca-284533468df5.png align="center")
    
5. Start the tomcat server,
    
    ```bash
    sudo starttomcat  # to start tomcat server
    sudo stoptomcat   # to stop tomcat server
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695146716927/5fab76b7-1a5f-40e7-9a4b-06c386714cec.png align="center")
    
    Copy the Public IP of the VM where Tomcat server is running and paste in URL in the below format,
    
    `https://<Public_IP>:8080/`
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695147011253/eef833ba-9e88-4164-90d1-3a6e28944b96.png align="center")
    
    Now Click on `Manage App` in the right side below Server Status, It'll ask for username and password. Enter the Username and Password which we created and it'll then open i.e., Username - admin and Password - admin1234,
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695147246936/f67cd20d-50e1-4c99-9b01-c94113206ec4.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695147399844/678800cb-9e2f-441f-8028-5f8276a53d59.png align="center")
    
6. This is where the application will run. To run application follow below steps,
    
    * Create `*.war/*.jar` file out of `pom.xml` using maven commands,
        
        ```bash
        mvn clean package 
        (or)
        mvn package
        ```
        
    * To know about Maven setup [click here](https://taraps.hashnode.dev/setup-and-basic-commands-for-maven).
        
    * After creating `*.war/*.jar`, Change the location of the file,
        
        ```bash
        sudo cp target/*.war /opt/apache-tomcat-9.0.65/webapps/
        ```
        
    * Now in URL, copy the public IP and write in below format.
        
        `https://<Public IP>:8080/*`  
        Replace "`*`" with appname written with `.jar/.war`. And App will open.
