Warning: Permanently added 'ec2-18-204-18-81.compute-1.amazonaws.com,18.204.18.81' (ECDSA) to the list of known hosts.
Welcome to Ubuntu 18.04.1 LTS (GNU/Linux 4.15.0-1021-aws x86_64)
...
ubuntu@ip-172-31-83-152:~$
Copy the code of your admin backend to your remote server
There are many ways to copy the code of your admin backend to a remote server. For example, you can use rsync command, or use a versioning system like git.
We strongly advise versioning the code of your admin backend using git and hosting it to a private repository on Github, Bitbucket, Gitlab, or other providers.
rsync
rsync is a utility for efficiently transferring and synchronizing files across computer systems, by checking the timestamp and size of files. It is commonly found on Unix-like systems and functions as both a file synchronization and file transfer program.
Rsync is typically used for synchronizing files and directories between two different systems.
(source: wikipedia ↗)
First, you need to initialize a git repository for the code of your admin backend. From the directory of your admin backend, simply run:
gitinit
Then, you can add all the files and create your first commit:
gitadd.gitcommit-am"First commit"
Finally, you can add your git remote and push the code on your favorite platform. To do so, first, create a new QuickStart repository on your GitHub account. Then run the following command after changing YourAccount to your account name:
Then, we will create a new DB user and schema from the remote server:
sudo-upostgrespsqlpostgres=# CREATE USER forest WITH ENCRYPTED PASSWORD 'secret';postgres=# CREATE DATABASE forest_demo;postgres=# GRANT ALL PRIVILEGES ON DATABASE forest_demo TO forest;postgres=# \q
List of relationsSchema | Name | Type | Owner--------+---------------------+----------+---------- public | Companies_id_seq | sequence | postgres public | addresses | table | postgres public | addresses_id_seq | sequence | postgres public | appointments | table | postgres public | appointments_id_seq | sequence | postgres public | companies | table | postgres public | customers | table | postgres public | customers_id_seq | sequence | postgres public | deliveries | table | postgres public | deliveries_id_seq | sequence | postgres public | documents | table | postgres public | documents_id_seq | sequence | postgres public | orders | table | postgres public | orders_id_seq | sequence | postgres public | products | table | postgres public | products_id_seq | sequence | postgres public | transactions | table | postgres public | transactions_id_seq | sequence | postgres(18rows)
Export the environment variables
You must export the environment variables FOREST_ENV_SECRETFOREST_AUTH_SECRET and DATABASE_URL. To do so, open and edit the file /etc/environment:
The FOREST_ENV_SECRET and FOREST_AUTH_SECRET environment variables will be given by Forest after creating a Production Environment from the interface. See how to get them here.
Then, you can restart your server to take these new variables into account or simply type:
for env in $( cat/etc/environment ); doexport $(echo $env |sed-e's/"//g'); done
Run your admin backend
From your admin backend's directory, simply type:
npmstart
> QuickStart@0.0.1 start /home/ubuntu/QuickStart
> node ./bin/www
🌳 Your back office API is listening on port 3000 🌳
🌳 Access the UI: http://app.forestadmin.com 🌳
Congrats, your admin backend is now running on production. But we strongly advise you to continue following the next steps. If you chose not to do it, you can go back to your Forest interface to create a Production Environment. Check out here how to do it.
The admin backend is by default listening on port 3310. Be sure you authorized the inbound traffic on this port or set up a web server (like NGINX) as a Reverse Proxy Server to use the port 80.
Manage Application with PM2
PM2 is a Production Runtime and Process Manager for Node.js applications with a built-in Load Balancer. It allows you to keep applications alive forever, to reload them without downtime and facilitate common Devops tasks. source: npmjs/pm2 ↗
Install PM2
sudonpminstallpm2-g
Run your admin backend using PM2
pm2startbin/www
(Optional) Set Up Nginx as a Reverse Proxy Server
Now that your admin backend is running and listening on localhost:3310, we will set up the Nginx web server as a reserve proxy to allow your admin panel's users access it.
sudoaptinstallnginx
To do so, edit (with sudo access) the file located /etc/nginx/sites-available/default and replace the existing section location / by this one:
Once you've completed the above steps, it does not mean your project is deployed to production on Forest Admin. To deploy to production, check out this section.