Skip to main content
Photo of DeepakNess DeepakNess

Self-hosting Plausible on a Hetzner VPS

Previously, I have always used Google Analytics to track visitors on my website, but this time, I decided to use Plausible analytics on my personal website. And mainly because of the following three reasons:

  1. Plausible is lightweight so doesn't affect the website loading speed much
  2. Unlike Google Analytics, Plausible is open-source and privacy-friendly, and
  3. The Plausible dashboard is user-friendly and shows essential data without complexity

Now, let's directly go to the self-hosting part. I will explain each and every step of self-hosting Plausible CE on a Hetzner VPS.

1. Set up a Hetzner VPS

If you don't have a Hetzner account, create one and get yourself verified by submitting an ID proof (I don't know if that's for everyone, but did have to submit). After logging in, go to console.hetzner.com page, create a Project and then go inside the Project to create a Server.

Click on the big Add Server button, and you will land on the below page. In this case, select the Cost-Optimized x86 (Intel®/AMD) version and then the CX23 server as shown in the screenshot. And this is more than enough to run Plausible, as it only requires 2GB of RAM to run efficiently, and we have 4GB here.

Create a new server on Hetzner

Below are the recommendations for other options on the page:

Click on the Create and Buy Now button and your server will be ready in a few minutes.

2. Install Plausible on the server

Now, you will have to connect to the server from your local Terminal and then install the Plausible CE on the server. To connect, you need to copy the IPv4 from the server that just got created, and run the following command from your terminal:

ssh root@YOUR_IPv4_ADDRESS

If you have the server connected via SSH, you just have press Enter again, and it will be connected. Otherwise, you might need to enter the server root password.

If you don't choose the SSH method, you will receive the root password via email.

After your terminal gets connect to the server, you can update the server by running the following command:

sudo apt update && sudo apt upgrade

It should look like below:

Update and upgrade the Hetzner server

After this completes, go to the Plausible community edition GitHub repo and follow the instructions. First, you need to run the following command to clone the repo (but make sure to check the latest command from the repo):

git clone -b v3.0.1 --single-branch https://github.com/plausible/community-edition plausible-ce

Now, go the plausible-ce folder by running below command:

cd plausible-ce

Create a .env file by running the following command:

touch .env

And then add BASE_URL and SECRET_KEY_BASE by running the following commands:

echo "BASE_URL=https://plausible.example.com" >> .env
echo "SECRET_KEY_BASE=$(openssl rand -base64 48)" >> .env

Make sure to replace BASE_URL with the URL where you want to host Plausible. You will also need to add an A DNS record with your server IP at Cloudflare (if you're using) or at your domain registrar.

You can also manually add BASE_URL and SECRET_KEY_BASE by running the nano .env command in the terminal.

Now, run the below commands one by one:

echo "HTTP_PORT=80" >> .env
echo "HTTPS_PORT=443" >> .env

And the run the following command:

cat > compose.override.yml << EOF
services:
  plausible:
    ports:
      - 80:80
      - 443:443
EOF

Finally, it's time to start the services with Docker Compose by running the below command:

docker compose up -d

And you will see something like below in the terminal:

Start Docker services for Plausible

Now, it's time to create user and add your website for tracking.

3. Start tracking visitors

First, you will need to create a user by visiting the BASE_URL you set earlier, something like https://plausible.example.com and create an account with your credentials.

And when asked, add the domain you want to track, something like deepakness.com, and go to the next step. You can enable optional measurements as shown below, and then Copy the script that's being shown in the box.

Adding a new site to Plausible

Now, go to your website and add the script somewhere between the <head>...</head> tags on your website, as explained in their docs. If you're having difficulties, you can also check this page for different installation options for websites with different tech-stacks.

Lastly, click on the Start collecting data button, and you should be good to go within a few minutes. Once correctly installed, you'll start seeing the data being shown in the dashboard.

And the best thing is, you can track users on multiple websites from the single Plausible dashboard.

While I have provided all the commands here in the post, I recommend checking on the Plausible community edition repo in case something changes.

That's it.

Hope this helps.

Comment via email