Articles

Set up Typesense on Ubuntu 22.04 including SSL

Typesense is a fast, typo-tolerant search engine that is easy to set up and use. In this tutorial, we will set up Typesense on a VPS and configure it to use SSL certificates. We will use a cheap VPS from Hetzner, but you can use any VPS provider that you prefer.

#Prerequisites

Before we start, you will need the following:

  • A VPS with Ubuntu 22.04 with at least 1GB of RAM and 1 CPU core
  • A domain name that you can point to your VPS
  • A basic understanding of Linux and the command line

#Step 1: Install Typesense

After your server is spun up, SSH into it and run the following commands:

Make sure to check the official documentation for the latest version of Typesense.

1# Update the package list and the packages
2apt update && apt upgrade -y
3 
4# Install Typesense
5# x64
6curl -O https://dl.typesense.org/releases/26.0/typesense-server-26.0-linux-amd64.tar.gz
7tar -xzf typesense-server-26.0-linux-amd64.tar.gz
8 
9# arm64
10curl -O https://dl.typesense.org/releases/26.0/typesense-server-26.0-linux-arm64.tar.gz
11tar -xzf typesense-server-26.0-linux-arm64.tar.gz

#Step 2: Set up SSL

Before proceeding, make sure that your domain is pointing to your VPS.

To set up SSL, we will use Certbot to generate SSL certificates for our domain. Run the following commands:

1apt install snapd
2snap install core && snap refresh core
3snap install --classic certbot
4certbot certonly --standalone -d your.domain.example.com

This will also set up auto renewal of your certificates. To make sure that Typesense will use the new certificates you will need to restart the service when the certificates have been renewed.

With your preferred text editor, open the Certbot renewal configuration file /etc/letsencrypt/renewal/your.domain.example.com.conf.

Add the following line to the file:

1renew_hook = systemctl reload typesense-server.service

#Step 3: Configure Typesense

Open the Typesense configuration file /etc/typesense/typesense-server.ini with your preferred text editor and change the lines with the comments. All other lines can be left as they are.

1[server]
2 
3api-address = 0.0.0.0
4api-port = 443 # Adjust the port
5api-key = api-key # Set a secure API Key
6log-dir = /var/log/typesense
7ssl-certificate = /etc/letsencrypt/live/your.domain.example.com/fullchain.pem # Path to the SSL certificate
8ssl-certificate-key = /etc/letsencrypt/live/your.domain.example.com/privkey.pem # Path to the SSL certificate key

#Step 4: Adjust firewall

As a security measure, you should adjust the firewall to only allow incoming traffic on the ports you need. Run the following commands:

1ufw allow 443
2ufw allow 80
3ufw allow 22
4ufw enable

This ensures, that only traffic from these ports are allowed.

#Step 5: Start Typesense

You are now ready to start Typesense!

Run the command below to start Typesense:

1systemctl start typesense-server.service

You may check if everything worked by opening the health check URL in your browser: https://your.domain.example.com/health.

If everything worked, you should see a JSON response like this:

1{
2 "ok": true
3}

I hope you found this article useful! 😊.