FACTS API
This installation guide is written for a Debian/Ubuntu based system. Specifically, an AWS Ubuntu 14.04 instance was used in June 2016, so please note that certain programs and commands may change over time.
-
Add the Oracle Java 8 dependency to the APT repository
-
sudo add-apt-repository ppa:webupd8team/java
-
Update the APT environment
-
sudo apt-get update
-
Install the necessary software for the API to run
-
sudo apt-get install nginx git mysql-server oracle-java8-installer
-
You will need to set a password for the MySQL server here and accept the Oracle Java 8 license agreements. 1. Please choose a suitably complex password.
-
Run the commands to secure the MySQL server installation. Follow the on-screen instructions.
-
mysql_secure_installation
-
mysql_install_db
-
Clone the latest FACTS repository and build it locally with a Gradle Wrapper command.
-
git clone https://github.com/cianyleow/facts
-
cd facts/facts
-
chmod u+x gradlew
-
./gradlew build
-
cd ../..
-
Create the user to run the application as and file system location to reside in.
-
sudo add user facts
1. Configure this user with a secure password. -
sudo mkdir /var/facts
-
sudo mv facts/facts/build/libs/facts-0.0.1-SNAPSHOT.jar /var/facts/
-
sudo chown facts:facts /var/facts/facts-0.0.1-SNAPSHOT.jar
-
sudo chmod 500 /var/facts/facts-0.0.1-SNAPSHOT.jar
-
Set up the database by running the
Install-DB.sql
file. You will need to create a user and database first. -
mysql -u root -p
-
Enter your password and you will enter the MySQL shell. Execute commands from here in this shell.
-
CREATE USER 'facts'@'localhost' IDENTIFIED BY '#PASSWORD#';
1. Replace #PASSWORD# with a suitably complex password. -
CREATE database facts
; -
GRANT INSERT, DELETE, SELECT, UPDATE ON facts.* FOR 'facts'@'localhost'
-
USE facts;
-
source facts/Install-DB.sql
-
Create the uploads folder and secure it.
-
sudo mkdir /var/facts/upload
-
sudo chown facts:facts /var/facts/upload
-
sudo chmod 600 /var/facts/upload
-
Configure the specific application properties
-
sudo mv /home/ubuntu/facts/application.properties /var/facts/application.properties
-
nano /var/facts/application.properties
1. Edit the details and set the MySQL facts user password, upload location (if different to above) and the JWT secret. 2. The JWT secret can be generated with the following command:openssl genrsa -des3 256
- Please choose a suitably strong passphrase.
- Copy the key itself, which looks like the below:
FFhdIezDCRo79SwavHcwqcPdCoAxM88h1LdPQYbWgENzwPotRygOcf69wQX2h+gLMRBGbstX1Ce0F57Vf0+zINIEshex5ZtegirXDsxeT39r3dadUSk4sHuT06qcPT2sdB+RNDJeVnbyFkJocJ3331yqW7buiue4UZDwItzVeJnDH4xePDgByiQHDfnQR5D7LBA5s5c3TdNJdnim7NqNYL0zcC/J997oOUhB6GJFgCM=
-
chown 400 /var/facts/application.properties
-
chmod 400 /var/facts/application.properties
-
Install the application as a system service in init.d
-
sudo ln -s /var/facts/facts-0.0.1-SNAPSHOT.jar /etc/init.d/facts
-
sudo mkdir /run/facts
-
sudo chown facts:root /run/facts
-
sudo su facts
1. Become the user facts and then start the facts application. 2./etc/init.d/facts
3. Then useexit
to go back to being your standard user. -
Install SSL certificates for server security.
-
Create self signed certificates: 1.
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/facts.key -out /etc/ssl/certs/facts.crt
2.sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
-
Install existing certificates: 1.
/etc/ssl/certs/facts.crt
2./etc/ssl/private/facts.key
3./etc/ssl/certs/dhparam.pem
-
Configure NGINX to operate as a reverse proxy and deliver the application over SSL.
-
sudo cp /home/ubuntu/facts/nginx/facts /etc/nginx/sites-available/
-
sudo cp -r /home/ubuntu/facts/nginx/snippets /etc/nginx
-
sudo ln -s /etc/nginx/sites-available/facts /etc/nginx/sites-enabled/
-
sudo nginx -t
-
sudo service nginx restart