Scratchwork.xyz, Part 2: Initial Setup Steps

First Steps

Get a domain

What do we need to do to set up a website like Scratchwork.xyz? First, we’ll need to actually own the domain. Technically we could just use the static IP address of our server, but try telling your friends to check it out *that* way! Go to a registrar like namecheap.com and find an address that’s available and speaks to you. Scratchwork was chosen because it’s a domain I use to test out concepts… like a scratch piece of paper. Be sure to get whois protection if it’s not included by default. We’ll be back to deal with linking this address to the server in a bit.

Get a server and set up the main user

Next, we’ll have to get a server ready to host the website. I used Digital Ocean, and set up the server using this tutorial from Tomi Mester, who has a nice set of free tutorials on his website on the subject of data science, as well as more in-depth courses available. If you’re following his tutorial, be sure to use his promo code as a thank you! I’ll briefly summarize the steps we need, because he includes some tools that aren’t relevant to us (in particular, we don’t need Jupyter nor R/RStudio): set up the cheapest tier of a Digital Ocean droplet using the most up-to-date Ubuntu long-term-service release (20.04, currently). Then, SSH from your desktop to the IP address of the droplet you just set up, using your root credentials.

You’ll then want to create a user for yourself with sudo privileges, so you don’t have to sign in using the root account. Re-log in as the named user; it’s best practices to not use the root account unless completely necessary. If you need root privileges for an operation, elevate a single command using sudo as a prefix; as long as your user is in the sudo group, you will be allowed to do so after typing in your password.

ssh root@$IP_ADDRESS
adduser $USER_NAME
usermod -aG sudo $USER_NAME
exit
ssh $USER_NAME@$IP_ADDRESS

Install key software

Install python3-pip using apt. We’ll use it later in Python’s virtual environments… a lot!

sudo apt update
sudo apt upgrade #this might take a while if you just installed the droplet
sudo apt install python3-pip

Install postgres SQL (on your server) and pgAdmin4 (on your desktop computer). I recommend carefully reading Tomi’s tutorial for this step. It includes switching users and some basic SQL commands. Pay attention to how pgAdmin uses port 5432 to communicate with the server. We will make sure we leave this port open when configuring the firewall to the server. If you have trouble, make sure you’re working on the right computer (the server for installing postgres, and your local computer for installing pgAdmin). Check the user@domain in your terminal if you’re not sure where you are!

Add a firewall.

It’s better to do this too early than too late. You’ll want to run something like:

sudo ufw allow ssh,http,https #typical, although right now only the ssh is urgent
sudo ufw allow 5432 #for postgres!
sudo ufw enable #set it active

Make sure to check you can still SSH into $USER_NAME@$IP_ADDRESS.

Relax

That was probably a lot of work if you aren’t familiar with Linux. But our framework is now established: we have a remote server with an SQL database. Next up is making sure we can host a website at our custom domain name.