First thing first. Assuming that you got an account at digitalocean, lets create a droplet. But before that add your ssh keys of your computers in Settings>Security>Add SSH Key.
1. Resolving SSH Keys
If you need to generate ssh key go here.
If you already have a ssh key then copy the content of your public key and paste it on digialocean.
2. Create Droplet
For this purpose I choose ubuntu 16.04 with 1 gigabyte if Ram. Choose it according to your need. And yes, DON’T forget to choose your pc (SSH Keys) when creating droplet. After creating droplet you’ll get an IP address of your machine. If you can’t find the IP, well consult your eye specialist 😉
3. Access to your droplet
If you are from mac or linux just open terminal and execute this command.
ssh [email protected]_address
If you copied your public key to digitalocean when creating the droplet you should get access at this point. If you forgot to do that you have to add your ssh key on the operating system manually.
4. Install Java
To install Java 8 execute the following command.
sudo apt-get update && sudo apt-get install openjdk-8-jdk
5. Install Mysql
sudo apt-get install mysql-server
On production server you’ll like to execute this following script. This changes some of the less secure default options for things like remote root logins and sample users. On older versions of MySQL, you needed to initialize the data directory manually as well, but this is done automatically now.
To test your mysql installation:
systemctl status mysql.service
6. Create Database and User
Login to mysql console
mysql -u root -p
CREATE DATABASE new_database;
OR (Considered as better practice)
CREATE DATABASE mydatabase CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Create Database User
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
Grant Privileges to that user
GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost'; FLUSH PRIVILEGES;
DROP USER ‘newuser’@‘localhost’;
Finally quit mysql using
As a convenient note, here’s the command to dump database
mysqldump -h hostname -u db_user -p dbname > dump.sql
As zipped archive
mysqldump -h hostname -u db_user -p dbname | zip core_dump_may_18.zip -
7. Uploading .jar file through scp
First build your spring boot application as a .jar file using this command.
mvn clean package -Dmaven.test.skip=true
When .jar file is built successfully copy this file to your server using scp.
scp [source] [destination]
in my case
scp /Volumes/workspace/workspace/springspace/hrsweb/target/hrs-0.0.1-SNAPSHOT.jar [email protected]_address:/root
It’ll start copying your file. To learn more about using scp go here.
You may want to change your filename after uploding it. this will do the trick.
mv old_file_name new_file_name
8. Run App
To run .jar file in the background (so that it isn’t closed when you ssh session is closed)
nohup java -jar appname.jar
You may need these commands during this process.
Find the process id of specific application.
ps aux | grep <process name>
and killing it
kill <process id>
Here’s a related article you may want to read.