The Gopher Wood PWA Journey, Part I: Setting up the Server

From choosing the hosting provider to setting it up for my app

Peter Wei Chen
4 min readMay 21, 2021

If you haven’t read the prequel to this article, you can read it here to get some context first.

Initially, I hosted the Gopher Wood app on an AWS EC2 instance, because it was pretty much the industry standard and it offered a free 1-year period with monthly balances, and I was paying around 0.5 USD each month during this time. However, in the 13th month and without me choosing any savings plan or reserved instances on AWS, the bill racked up to a whopping ~40 USD. I quickly discovered that AWS is not for SMEs. After some research, I decided to use Hostinger, which may not be the biggest name out there for SME web hosting, but definitely seemed like one of the strongest in terms of the value it offered. Since Sapper apps runs on Node.js, I cannot choose any of the shared hosting options provided by Hostinger. The next best option is their VPS (Virtual Private Servers) plans. There are 6 tiers, of which I chose the 1st one, keeping in mind that I can upgrade it to the next tier when/if it becomes necessary.

Anyway, to set up a VPS on Hostinger is pretty straightforward and self-explanatory. I chose the best server location for me, and chose Ubuntu 20.04 64-bit as my operating system. Next, I needed to set up SSH access so I can actually set up my server. Here are the steps to do that:

Generating an SSH key pair

To start off, the recommended method of accessing a server via SSH is with an SSH key. To do so, I first needed a public/private key pair. I opened up my terminal and entered ssh-keygen -t rsa. This generates a public/private key pair that can then be used for SSH access to my server. It prompts you to choose the location where you wish to save your key pair, as well as any passphrase you want to enter each time you use this key with SSH. The passphrase is just for an extra layer of security, so I have currently omitted it and just pressed enter instead to not have any passphrase.

Next, I copied the key over to my server by running ssh-copy-id -i ~/.ssh/mykey user@host in order to do this. ~/.ssh/mykey is the path where I stored my key when I generated it, and user@host is simply my user name and server IP. If you haven’t connected to your server before, the user name is most likely going to be root. Once this is done, you can simply run ssh user@host in order to SSH into your server.

Adding an administrative user

Once in the server, it is recommended to add another user besides the root user (which is likely the user with which you first logged in), since the root user has access to everything in the server, and you can accidentally perform something destructive that is hard to undo. It’s thus much safer to create another user and simply grant the user administrative rights. I simply consulted this great article by Digital Ocean that walks you through the process in great detail.

Note: the article above uses ufw as the firewall of choice, but Hostinger’s Ubuntu VPS doesn’t seem to have ufw installed by default, so you can refer to another guide by Digital Ocean to install it.

Setting up other components

Next up, I needed to install all the necessary tools to build and run my app, to run it, and to serve it to the HTTP/HTTPS ports so that I can point my domain to the server and actually see my app being returned. Again, Digital Ocean had a series of guides that were useful to me:

Linking to my domain

The last thing to do was to point my domain to the server. This should be a simple thing to do — simply edit your domain’s DNS record and point it to the IP address of the VPS, and voila, you should see your app!

This here is mine 😄

Gopher Wood Clinic’s Landing Page
Gopher Wood Clinic’s landing page

Quick summary

And that’s it! To review, let’s see what we did:

  • Set up SSH access to server
  • Create administrative user for server
  • Set up other components such as Node/NPM, Git, MariaDB, PM2, and NGinx
  • Point my domain to the server’s IP

At the end of it, I was able to see the Gopher Wood app at https://gopherwoodclinic.org. Feel free to check it out too!

--

--

Peter Wei Chen
0 Followers

Passionate problem-solver. Homeschooled till full-ride scholarship at NYUAD. Full-time tech lead @ PwC Middle East and part-time solution architect / web dev.