I decided to self-host Plausible because I want to keep the cost of maintaining this site as low as possible. So here are some resources to help you configure Plausible for free on Amazon EC2.

Plausible is lightweight and privacy-friendly analytics for people who want to see only the essential stats of their site.

If you’re not concerned with the pricing, you can subscribe to their basic plan for $6/month and track the page views up to 10k per month. Choosing this option means you can focus on growing your projects and spend less time managing the server running Plausible.

The main advantage of self-hosting Plausible is the cost. You can eliminate the cost of analytics by creating a virtual machine on the cloud. Thanks to the folks at Plausible for making the project open-source; you can easily create a free instance on Amazon EC2 and get Plausible running in hours.

Getting Started with Amazon EC2

Amazon EC2 is a web service that lets you create virtual machines (known as instances) in the cloud. They’re also known as Cloud Server.

Other cloud servers also offer free-tier, but I’m going to use Amazon EC2 because I’ve already used Amazon S3 for my static documents. Sign in with your Amazon account to access the dashboard.

Follow these steps to create a new instance that we will use to set up Plausible.

  1. Select “Instances” from the sidebar
  2. Select “Launch Instances”
  3. Enable “Free-tier only” filter in the sidebar
  4. Choose Ubuntu Server 20.04 LTS (HVM) 64-bit (x86)
  5. Choose the free tier option in the list
  6. Select “Review and Launch” to complete the instance setup
  7. Save the PEM certificate somewhere safe

You’ll be asked to name the PEM certificate. I name the certificate as aws-ubuntu and save it in ~/.ssh directory. Keep the certificate safe because you will need it whenever you want to access the server.

Before connecting to the instance you’ve just created, you need to set the inbound security rules to accept requests made to port 80 and 443. You can click on the running instance and select the Security tab under the instance summary. Next, click on the security groups and set the following inbound rules.

TypeProtocolPort rangeSource
HTTPTCP800.0.0.0/0
SSHTCP220.0.0.0/0
HTTPSTCP4430.0.0.0/0

Connecting Instance Through SSH

Make sure you can connect to the instance through SSH. You can follow the instructions under the “Connect” tab to get started. I personally use macOS built-in Terminal application to access the remote server.

Here’s a command you enter into Terminal with the information you copied from the “Connect” tab.

ssh -i "aws-ubuntu.pem" [email protected]

The command you want to paste will look different from the one you see above. Pay attention to the name of the PEM certificate and the remote address to access your server.

Notes on Setting Up Plausible

Tyler has written a concise tutorial to help you setting up Plausible on a Ubuntu Server. You should be able to get Plausible running if you follow each step carefully.

Here are some notes you want to pay attention to when setting up Plausible.

Executing commands as a root user is not exactly a best practice when it comes to managing a remote server. You usually want to set up a separate user account under the sudo group. However, for a personal project like this, you can skip creating a user account if you’re not comfortable with accounts management.

Public IPv4 address is the IP address you want to set up as A record under the DNS configuration. For example, I access my dashboard from stats.sayzlim.net, so I will have to set the A record to point to my server’s public IP address. Make sure to set the proxy status to DNS only if you’re on CloudFlare.

Add DISABLE_REGISTRATION=true to plausible-conf.ev file to prevent people signing up a new account on your self-hosted Plausible.

Run docker ps to list all the active containers. Plausible will only work if those four containers are running. I spent hours debugging because I entered a wrong secret key. It turned out one of the containers will not run if the key length is not Base64.

hosting_plausible_1
hosting_plausible_events_db_1
hosting_mail_1
hosting_plausible_db_1

Be patient when setting up SSL certificates with certbot. Verify that the server_name in /etc/nginx/sites-enabled/plausible has been set to the correct URL. You can verify the A record by running the nslookup command. For example, I will run nslookup stats.sayzlim.net and expect the public IP address in the result.

Server:		192.168.1.1
Address:	192.168.1.1#53

Non-authoritative answer:
Name:	stats.sayzlim.net
Address: 3.143.214.18

Send me a Twitter DM if you encounter any problems while trying to get Plausible configured on Amazon EC2. Also, make sure to sponsor Plausible if you’ve successfully self-hosted it on your server.