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.
Before we start, you will need the following:
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# arm6410curl -O https://dl.typesense.org/releases/26.0/typesense-server-26.0-linux-arm64.tar.gz11tar -xzf typesense-server-26.0-linux-arm64.tar.gz
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 snapd2snap install core && snap refresh core3snap install --classic certbot4certbot 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
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.04api-port = 443 # Adjust the port5api-key = api-key # Set a secure API Key6log-dir = /var/log/typesense7ssl-certificate = /etc/letsencrypt/live/your.domain.example.com/fullchain.pem # Path to the SSL certificate8ssl-certificate-key = /etc/letsencrypt/live/your.domain.example.com/privkey.pem # Path to the SSL certificate key
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 4432ufw allow 803ufw allow 224ufw enable
This ensures, that only traffic from these ports are allowed.
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": true3}
I hope you found this article useful! 😊.