blog.thms.uk

Installing and configuring Plausible Analytics Community Edition on Ubuntu

I’ve been looking for some analytics functionality for my blog for a little while. I don’t need much, since I’m neither monetising nor trying to SEO-ify this blog, but I’m simply curious what people are interested in, how many people actually read my blog etc.

I’m also not interested in Google Analytics, because I really don’t like Google (and I need to use Google Analytics for work and hate it), and Matomo seems overkill for my needs.

After some research I found Plausible. It seems pretty cool, easy enough to use, and privacy friendly, so I wouldn’t need a cookie popup. I was delighted when I saw they have a free Community Edition for self-hosting, because it would be cheaper and more fun than to use their service.

So here is how I set up my Plausible Community Edition:

Pre-requisites

You need a server. I use Hetzner and specifically chose their CAX11 server, which is the cheapest they offer (€4.95 per month for 2 vCPUs, 4 GB RAM, 40 GB disk). This has plenty of CPU and RAM for my use case - though I might run out of disk space, I suppose …

My server is running Ubuntu 24.04 LTS.

Basic security setup

After buying the server, here is the bare minimum you should do with every new server you get:

You don’t want to use the root user day-to-day, so create a new user, add the user to the root group, and add your SSH key (replace michael with your chosen username throughout):

adduser michael
usermod -aG sudo michael
mkdir /home/michael/.ssh
cp .ssh/authorized_keys /home/michael/.ssh/
chown -R michael:michael /home/michael/.ssh

At this stage you want to log out of the root user, and log in using your newly created user. After you have confirmed that this works, disable SSH login for the root user:

sudo nano /etc/ssh/sshd_config

Find the line that says PermitRootLogin yes and change it to PermitRootLogin no.

Restart the SSH server:

sudo systemctl restart sshd

You absolutely also want a firewall (I use Hetzner’s cloud firewall) that allows only your SSH port, ports 80 and 443.

Finally, enable unattended-upgrades to make sure system packages are always kept up to date. I recommend enabling automated reboots too!

Install Docker

Plausible Community Edition is managed using Docker, so you need to install it:

# Update everything
sudo apt update
# Install requirements
sudo apt install apt-transport-https ca-certificates curl software-properties-common
# Add Docker's GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# Add Docker repo
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
# Finally, install docker:
sudo apt install docker-ce

Now add your user to the docker group, so that you can execute docker commands (replace michael with your username again):

sudo usermod -aG docker michael

Installing Plausible Community Edition

You are now ready to install Plausible Community Edition on your server, so lets get cracking:

Firstly, clone the git repo, and change into the directory (replace v2.1.4 with whatever is currently the latest version):

git clone -b v2.1.4 --single-branch https://github.com/plausible/community-edition plausible-ce
cd plausible-ce

Now, create and configure the environment file (replace analytics.thms.uk with your chosen domain):

touch .env
echo "BASE_URL=https://analytics.thms.uk" >> .env
echo "SECRET_KEY_BASE=$(openssl rand -base64 48)" >> .env
echo "HTTP_PORT=80" >> .env
echo "HTTPS_PORT=443" >> .env

Create a composer override file to expose your services to the outside world:

nano compose.override.yml

Paste the following content:

services:
  plausible:
  ports:
    - 80:80
    - 443:443

Save and exit.

Finally, start up the service:

docker compose up -d

Congratulations! Plausible should now be up and running. Visit your base url specified above, and follow the prompts to create your user, and configure your site.

Configure the Google Integration

If you use Google Search Console, you can configure the Google Integration, so that you can pull in data from Search Console about search terms, which is really rather neat.

If you already got a Google Cloud account with an OAuth client, you can simply paste your GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET into the .env file, restart your docker service with docker compose up -d, and follow the prompts in Plausible’s Site Settings > Integrations screen.

If you have no idea what any of this means, they have very detailed instructions in the Plausible Wiki: Google Integration.

Final thoughts

Wow, that was easy! It took me about half an hour or to set this all up, starting from just a bare Ubuntu VPS.

I do like Plausible! It’s dead easy to install, setup, and use, and provides some basic stats about visitors to my blog, while being privacy respecting.

It’s also quick and pretty.

And, finally, if you run it on your own domain (and don’t name it analytics, plausible or something similar) it’ll be unlikely to be blocked by ad-blockers, which means you get good insights into actual traffic.

I was absolutely amazed that I seem to be getting 30-40 visits a day on my blog! I would’ve never expected to get even half that!