Developer Guide
Other documentationsDemoCommunityGitHub
  • Forest Admin
  • Getting Started
    • Quick start
    • Development workflow
  • Reference Guide
    • How it works
      • Environments
      • Developing on Forest Admin
        • Using branches
        • Deploying your changes
        • Forest CLI commands
          • init
          • login
          • branch
          • switch
          • set-origin
          • push
          • environments:reset
          • environments:create
          • deploy
          • schema:diff [beta]
        • Express packages
    • Models
      • Enrich your models
      • Relationships
        • Create a Smart relationship
          • GetIdsFromRequest
        • Smart Relationship Examples
          • Smart hasMany relationship in mongoDB
    • Actions
      • Create and manage Smart Actions
        • Use a Smart Action Form
        • Use a Smart Action Intent
      • Smart Action Examples
        • Calculate the distance between two string addresses
        • Impersonate a user
        • Create a record with a multiselect through a many-to-many relationship
        • Handle enums with alias labels in a smart action
        • Dropdown with list of values in smart action form
        • Custom dynamic dropdown in a form using smart collections
        • Refresh hasMany relationship in smart action
        • Smart segment to restrict access to an action on a record details view
        • BelongsToMany edition through smart collection
        • Upload files to amazon s3
        • Upload several files with the File Picker
        • Retrieve smart field info in a smart action
        • Smart action to create several records from the input of a single smart action form
        • Add many existing records at the same time (hasMany-belongsTo relationship)
        • Call a webhook with record ids
        • Bulk update records
    • Smart Fields
      • Smart Field Examples
        • Add an HTML credit card as a smart field in a summary view
        • Display field with complex info in html format (rich text editor)
        • Generate signed urls to display S3 files in a smart field
        • Print a status object in a single line field
        • Sort by smart field
        • Sort by smart field that includes value from a belongsTo relationship
        • Add fields destined to the create form
        • Add validation to a smart field edition
        • Display smart field as progress bar using rich text editor
        • Update point geometry field using a smart field and algolia api
    • Smart Collections
      • Examples
        • Create a Smart Collection with Amazon S3
        • Smart relationship between model and stripe cards
        • Create records from a Smart collection
        • Searchable smart collection with records fetched from hubspot API
      • Serializing your records
    • Routes
      • Default routes
      • Extend a route
      • Override a route
    • Integrations
      • Stripe
      • Mixpanel
      • Intercom
      • Elasticsearch
        • Interact with your Elasticsearch data
        • Elasticsearch service/utils
        • Another example
      • Zendesk
        • Authentication, Filtering & Sorting
        • Display Zendesk tickets
        • Display Zendesk users
        • View tickets related to a user
        • Bonus: Direct link to Zendesk + change priority of a ticket
      • Dwolla
        • Display Dwolla customers
        • Display Dwolla funding sources
        • Display Dwolla transfers
        • Link users and Dwolla customers
        • Dwolla Service
      • Razorpay
      • Hubspot
        • Create a Hubspot company
        • Display Hubspot companies
      • Twilio
        • Send an SMS with Twilio and Zapier
      • Azure Table Storage
      • Slack
        • Send Smart Action notifications to Slack
      • Algolia
        • Geocode an address with Algolia
    • Smart Views
      • Create a Map view
      • Create a Calendar view
      • Create a Shipping view
      • Create a Gallery view
      • Create a custom tinder-like validation view
      • Create a dynamic calendar view for an event-booking use case
      • Create a custom moderation view
    • Smart Segments
    • Scopes
      • Create a scope more than one level away based on a Smart field
      • Scope on a smart field extracting a json's column attribute
    • Performance
    • Charts
      • Create an API-based Chart
      • Create a Smart Chart
      • Create Charts with AWS Redshift
  • Extra help
    • Setup
      • Install
      • Connecting Forest Admin to Your Database (Forest Cloud)
      • Forest Admin IP white-listing (Forest Cloud)
      • Why HTTPS is necessary even locally
      • Troubleshooting
      • Prevent permission errors at installation
      • Deploy your admin backend to AWS
      • Deploy your admin backend on Heroku
      • Deploy your admin backend to Ubuntu server
      • Deploy your admin backend to Google Cloud Platform
      • Install Forest Admin on a remote machine
      • Use Forest Admin with a read-only database
      • Configuring CORS headers
      • Running Forest Admin on multiple servers
      • Flatten nested fields (MongoDB)
    • Upgrade
      • Upgrade notes (Rails)
        • Upgrade to v9
        • Upgrade to v8
        • Upgrade to v7
        • Upgrade to v6
        • Upgrade to v5
        • Upgrade to v4
        • Upgrade to v3
      • Upgrade notes (SQL, Mongodb)
        • Upgrade to v9
        • Upgrade to v8
        • Upgrade to v7
        • Upgrade to v6
        • Upgrade to v5
        • Upgrade to v4
        • Upgrade to v3
      • Update your models' definition
      • Monitor your Forest's status
      • Manage your Forest Admin environments programmatically
      • Changing your domain name
      • Migrate to the new role system
      • Push your new version to production
    • Databases
      • Use a demo SQL database
      • Use a demo MongoDB database
      • Populate a postgreSQL database on Heroku
      • Connect to a read replica database
      • Plug multiple schemas
      • Add new databases
      • Manage SQL views
    • Settings
      • Customize your /forest folder
      • Disable automatic Forest Admin schema update
      • Include/exclude models
      • Display extensive logs
      • Laravel specific settings
    • Releases Support
    • Other documentations
Powered by GitBook
On this page

Was this helpful?

  1. Extra help
  2. Setup

Deploy your admin backend to Ubuntu server

The goal of this tutorial is to help people deploy their admin backend to Ubuntu server.

PreviousDeploy your admin backend on HerokuNextDeploy your admin backend to Google Cloud Platform

Last updated 1 year ago

Was this helpful?

Please be sure of your agent type and version and pick the right documentation accordingly.

This is the documentation of the forest-express-sequelize and forest-express-mongoose Node.js agents that will soon reach end-of-support.

forest-express-sequelize v9 and forest-express-mongoose v9 are replaced by v1.

Please check your agent type and version and read on or switch to the right documentation.

This is still the latest Ruby on Rails documentation of the forest_liana agent, you’re at the right place, please read on.

This is the documentation of the django-forestadmin Django agent that will soon reach end-of-support.

If you’re using a Django agent, notice that django-forestadmin v1 is replaced by v1.

If you’re using a Flask agent, go to the v1 documentation.

Please check your agent type and version and read on or switch to the right documentation.

This is the documentation of the forestadmin/laravel-forestadmin Laravel agent that will soon reach end-of-support.

If you’re using a Laravel agent, notice that forestadmin/laravel-forestadmin v1 is replaced by v3.

If you’re using a Symfony agent, go to the v1 documentation.

Please check your agent type and version and read on or switch to the right documentation.

Deploy your admin backend to Ubuntu server

Connect to your Ubuntu server using SSH

Before starting anything, you have to make sure you're able to connect to your server using SSH.

ssh -i ~/.ssh/aws.pem ubuntu@ec2-18-204-18-81.compute-1.amazonaws.com
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 to version the code of your admin backend using git and host 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: )

The syntax used is rsync OPTIONS SOURCE TARGET.

rsync -avz -e "ssh -i ~/.ssh/aws.pem -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --exclude=node_modules --exclude=.git --progress QuickStart ubuntu@ec2-18-204-18-81.compute-1.amazonaws.com:~/

In the example above, we use a SSH connection to transfer the file and we connect to the remote server using an identity_file (a private key).

Option
Description

-a

archive mode; same as -rlptgoD (no -H)

-v

increase verbosity

-z

compress file data during the transfer

-e

specify the remote shell to use

--exclude=PATTERN

exclude files matching PATTERN

--progress

show progress during transfer

Once done, you can find the code of your admin backend on the home directory of your remote server.

ssh -i ~/.ssh/aws.pem ubuntu@ec2-18-204-18-81.compute-1.amazonaws.com
ubuntu@ip-172-31-83-152:~$ cd Quickstart/
ubuntu@ip-172-31-83-152:~/QuickStart$ ls -l
total 5116
-rw-r--r-- 1 ubuntu ubuntu    1386 Oct 22 08:11 app.js
-r-------- 1 ubuntu ubuntu    1692 Oct 23 12:51 aws.pem
drwxr-xr-x 2 ubuntu ubuntu    4096 Oct 12 10:19 bin
-rw-r--r-- 1 ubuntu ubuntu 5126311 Oct 12 11:20 database.dump
drwxr-xr-x 2 ubuntu ubuntu    4096 Oct 19 11:49 forest
drwxr-xr-x 2 ubuntu ubuntu    4096 Oct 19 12:22 models
-rw-r--r-- 1 ubuntu ubuntu   69568 Oct 22 07:30 package-lock.json
-rw-r--r-- 1 ubuntu ubuntu     717 Oct 22 07:30 package.json
drwxr-xr-x 2 ubuntu ubuntu    4096 Oct 12 10:19 public
drwxr-xr-x 2 ubuntu ubuntu    4096 Oct 22 07:48 routes
drwxr-xr-x 2 ubuntu ubuntu    4096 Oct 19 11:53 serializers
drwxr-xr-x 2 ubuntu ubuntu    4096 Oct 19 11:55 services
ubuntu@ip-172-31-83-152:~/QuickStart$

git

First, you need to initialize a git repository for the code of your admin backend. From the directory of your admin backend, simply run:

git init

Then, you can add all the files and create your first commit.

git add .
git commit -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:

git remote add origin git@github.com:YourAccount/QuickStart.git
git push -u origin master

Now, you can connect to your remote server using SSH and clone the repository using the HTTPS method.

ssh -i ~/.ssh/aws.pem ubuntu@ec2-18-204-18-81.compute-1.amazonaws.com
git clone https://github.com/YourAccount/QuickStart.git
Cloning into 'QuickStart'...
remote: Enumerating objects: 34, done.
remote: Counting objects: 100% (34/34), done.
remote: Compressing objects: 100% (21/21), done.
remote: Total 34 (delta 7), reused 34 (delta 7), pack-reused 0
Unpacking objects: 100% (34/34), done.

That's it. Your admin backend's code is available on your remote server.

ubuntu@ip-172-31-83-152:~$ cd QuickStart/
ubuntu@ip-172-31-83-152:~/QuickStart$ ls -l
total 5112
-rw-rw-r-- 1 ubuntu ubuntu    1386 Oct 23 13:42 app.js
drwxrwxr-x 2 ubuntu ubuntu    4096 Oct 23 13:42 bin
-rw-rw-r-- 1 ubuntu ubuntu 5126311 Oct 23 13:42 database.dump
drwxrwxr-x 2 ubuntu ubuntu    4096 Oct 23 13:42 forest
drwxrwxr-x 2 ubuntu ubuntu    4096 Oct 23 13:42 models
-rw-rw-r-- 1 ubuntu ubuntu   69568 Oct 23 13:42 package-lock.json
-rw-rw-r-- 1 ubuntu ubuntu     717 Oct 23 13:42 package.json
drwxrwxr-x 2 ubuntu ubuntu    4096 Oct 23 13:42 public
drwxrwxr-x 2 ubuntu ubuntu    4096 Oct 23 13:42 routes
drwxrwxr-x 2 ubuntu ubuntu    4096 Oct 23 13:42 serializers
drwxrwxr-x 2 ubuntu ubuntu    4096 Oct 23 13:42 services
ubuntu@ip-172-31-83-152:~/QuickStart$

Install dependencies

First, you have to make sure you have Node.js and NPM correctly installed on your server.

sudo apt update
sudo apt install nodejs npm

Then, you will be able to install all the dependencies listed on the package.json file.

npm install

Create the database

PostgreSQL

This step is optional if you already have a running database.

First, you need to install PostgreSQL:

sudo apt-get install postgresql postgresql-contrib

Then, you will be able to connect to the database server:

sudo -u postgres psql
psql (10.5 (Ubuntu 10.5-0ubuntu0.18.04))
Type "help" for help.

postgres=

Now, we can export the database from your local environment (your computer) to import it to your Ubuntu server.

For security reason, we will not allow remote connections to this database. This is why transfer the database dump to the remote server using rsync.

From your computer:

PGPASSWORD=secret pg_dump -h localhost -p 5416 -U forest forest_demo --no-owner --no-acl -f database.dump
rsync -avz -e "ssh -i ~/.ssh/aws.pem -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress database.dump ubuntu@ec2-18-204-18-81.compute-1.amazonaws.com:~/

Then, we will create a new DB user and schema from the remote server:

sudo -u postgres psql
postgres=# CREATE USER forest WITH ENCRYPTED PASSWORD 'secret';
postgres=# CREATE DATABASE forest_demo;
postgres=# GRANT ALL PRIVILEGES ON DATABASE forest_demo TO forest;
postgres=# \q

And finally import the dump:

PGPASSWORD=secret psql -U forest -h 127.0.0.1 forest_demo < database.dump

That's it, your database is now fully imported.

PGPASSWORD=secret psql -U forest -h 127.0.0.1 forest_demo
psql (10.5 (Ubuntu 10.5-0ubuntu0.18.04))
Type "help" for help.

forest_demo=>
forest_demo=> \d
                 List of relations
 Schema |        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
(18 rows)

Export the environment variables

You must export the environment variables FOREST_ENV_SECRET FOREST_AUTH_SECRET and DATABASE_URL. To do so, open and edit the file /etc/environment:

sudo vim /etc/environment
/etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
FOREST_ENV_SECRET=2417520743be37a9c5af198c018e0ddee9b7c41de1ccb8e76c9d027faa74059e
FOREST_AUTH_SECRET=Piq7a9Kv5anLbK4gj81rirsLhfaJ0pdL
DATABASE_URL=postgres://forest:secret@127.0.0.1/forest_demo

Then, you can restart your server to take these new variables into account or simply type:

for env in $( cat /etc/environment ); do export $(echo $env | sed -e 's/"//g'); done

Run your admin backend

From your admin backend's directory, simply type:

npm start
> 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  🌳

Manage Application with PM2

Install PM2

sudo npm install pm2 -g

Run your admin backend using PM2

pm2 start bin/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.

sudo apt install nginx

To do so, edit (with sudo access) the file located /etc/nginx/sites-available/default and replace the existing section location / by this one:

/etc/nginx/sites-available/default
location / {
  proxy_pass http://localhost:3000;
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection 'upgrade';
  proxy_set_header Host $host;
  proxy_cache_bypass $http_upgrade;
}

Then, restart nginx:

sudo systemctl restart nginx

That's it, your admin backend is now listening on the port 80. Make sure your firewall allows inbound traffic from this port.

The FOREST_ENV_SECRET and FOREST_AUTH_SECRET environment variables will be given by Forest after creating a production environment from the interface. .

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. .

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 to use the port 80.

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: ​

We now require that you configure HTTPS (port 443) on your admin backend service for security reasons. ​

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 .

@forestadmin/agent
forestadmin-agent-django
forestadmin-agent-flask
forestadmin/laravel-forestadmin
forestadmin/symfony-forestadmin
wikipedia
See how to get them here
Check out here how to do it
Reverse Proxy Server
npmjs/pm2
http://nginx.org/en/docs/http/configuring_https_servers.html
this section