Deploy a JAVA Web Application in DigitalOcean

Image for post
Image for post
Source: https://blog.digitalocean.com/sammy-the-shark-gets-a-birthday-makeover-from-simon-oxley

This article explains how to deploy a JAVA web application which have MySQL database in DigitalOcean. You have to do following steps in order.

  1. Create a Droplet with Ubuntu 16.04
  2. Install Apache Tomcat 8
  3. Install MySQL
  4. Install phpMyAdmin
  5. Set Up Apache Virtual Hosts

These steps are already explained as Tutorials in DigitalOcean community. So, I will use those tutorials and connect them with the required modifications.

Step 1

First you have to create and DigitalOcean and create a droplet which is a virtual private server. This is explained in the following tutorial with several steps and you have to follow each and every step of this.

Now you can access,
* Tomcat default splash page : http://<droplet-IP>:8080
* Tomcat manager : http://<droplet-IP>:8080/manager

Step 2

Next you have to install Apache Tomcat 8 on Ubuntu 16.04 droplet. For this you have to follow each and every step of this tutorial one by one.

If the Step 3 in this tutorial not work for you, then the easiest way to solve this is that manually download from https://tomcat.apache.org/download-80.cgi and SCP the inside directory set and files into /opt/tomcat directory of the droplet.

Step 3

Next you have to install MySQL in order to setup you database in the droplet. For this you have to follow each and every step of this tutorial one by one.

Step 4

Next step is to install phpMyAdmin in order to manage the databases in the droplet. For this you have to follow each and every step of this tutorial one by one.

Now you can access phpMyAdmin : http://<droplet-IP>/phpmyadmin

Step 5

The final step is to setup your virtual host which redirects the request coming to http://<droplet-IP> or http://<droplet-IP>:80 into http://<droplet-IP>:8080 where the JAVA web application you are going to deploy in your droplet.

You need to have Apache installed in order to work through these steps. You can get Apache installed on your server through sudo apt-get install apache2

Before configuring Apache, you should enable the necessary modules. a2enmod proxy
a2enmod proxy_http

Next, you are going to modify the default configuration file 000-default.conf inside /etc/apache2/sites-enabled to set up "proxying" functionality.

Run the following command to edit the default Apache virtual host using the nano text editor: nano /etc/apache2/sites-enabled/000-default.conf

Here, you will be defining a proxy virtual host using mod_virtualhost and mod_proxy together. Copy-and-paste the below block of configuration, amending it to suit your needs:

<VirtualHost *:*>
ProxyPreserveHost On
ProxyPass / http://0.0.0.0:8080/
ProxyPassReverse / http://0.0.0.0:8080/
ServerName localhost
</VirtualHost>

Press CTRL+X and confirm with Y to save and exit.

Once you are done with your configuration, you will need to restart the cloud server for the changes to go into effect. Execute the following command to restart Apache: service apache2 restart

And that’s it! Your installation of prerequisites are complete now! Your are now free to deploy your own Java web applications using Tomcat manager.

Since you have configured port 80 to redirect into 8080 now you can access Tomcat manager using http://<droplet-IP>/manager
Create the war file of your web application. Then go to WAR file to deploy section of Tomcat manager and upload the war file and Deploy.

That’s it! You are done with deploying your JAVA web application in DigitalOcean.

Now you can access your web application : http://<droplet-IP>

Written by

Tech Enthusiast | Software Engineer @ WSO2 | Computer Science Engineering @ UoM | Rotaractor | Maliyadeva College

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store