How to Install Plausible Google Analytics Open Source Alternative

how to install plausible

Table Of Contents

Share Article

You may want to self-host your analytics alternative because of GDPR regulations or just because you don’t want Google to know everything about your website. In this article, we will see how we can set up Plausible on our own VPS server.

I don’t want to share my traffic stats with Google or anyone and because of this, I would like to host my own Analytics alternative. Plausible is a light one that has all the features I need.

If you are interested to see how Hetzner is comparing with DigitalOcean you should see: DigitalOcean VS Hetzner: Which is The Best VPS Provider

If you are interested to see how the best VPS providers compare check the DigitalOcean vs Vultr vs Hetzner article.

Plausible offers the possibility to self-host it and have access to the basic things like visitors, live visitors, pages, device, country, you can set also goals.

In this article, we will install Plausible in a docker container and we will use a reverse proxy to add SSL and use a custom subdomain. You can watch the below video to see a step-by-step guide with everything.

1. Install a VPS Server

To self-host Plausible you need a VPS server where you can install the app. You can use digitalocean, Vultr or Hetzner.

Plausible is lightweight and will not use a lot of resources but still will need some in the function of the visitors and number of sites you have. You can start with the lowest plan and move upon any of the VPS providers.

In the video, you will see how I am installing an Ubuntu 21.10 on Digitalocean, is not hard you just need to go and choose a droplet. For a more affordable option to DigitalOcean, you can check this Hetzner Review.

2. Install steps for Plausible on Ubuntu 21.10

Add swap if VPS is not having any. Usually, VPS servers on the digital ocean don’t have a swap so you need to add some in case there will not be enough memory on the server swap to be used.

You can follow: How to Add Swap Space on Ubuntu 20.04 | Linuxize

Next, we will move to the exact steps with the commands we need to run and have Plausible set up on our web server. For detailed instructions, you can watch my video.

Install needed software, like git, Nginx, we will also upgrade everything and restart the server:

sudo apt update
sudo apt upgrade
sudo reboot
sudo apt install nginx git

Docker install:

Next, we need to install docker and docker-compose. Plausible will create some containers from where it will run. You can follow my steps and in case of issues follow docker official documentation.

Official doc: docs.docker.com/engine/install/ubuntu and Install Docker Compose | Docker Documentation

To install Docker, we first need to add its official GPG key, and set up the stable repository:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu focal stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt-get install docker-ce docker-ce-cli docker-compose containerd.io

Use the cd command to navigate into the /opt directory:

cd /opt/

Clone the repo into a plausible directory

sudo git clone https://github.com/plausible/hosting plausible

Navigate to Plausible directory:

cd plausible

Generate a random hash. You will need it in the next step when you edit the config files.

openssl rand 64 | base64 -w 0 ; echo

Edit the config file plausible-conf.env

Here we add the admin email and websites name that we are going to use for our plausible installation. In this config file, we can also add our email SMTP details that can be used. The official documentation has the bellow details: Configuration options | Plausible docs

[email protected] #replace with your email (should be working one)
ADMIN_USER_NAME=admin #name it anyway you want
ADMIN_USER_PWD=adm1nPassword123 #the stronger, the better
BASE_URL=https://analytics.example.com #this is your URL, use the domain attached to this instance's IP, must start with http/https
SECRET_KEY_BASE=ZN5JhjiQ+TGJP8hMRerTAXtu/7bmd3eZitRaIqlvaQXdkHrODe6wxSLN4izMOPbqpRnTpghI6FJX3Bvf8RVMRQ== #generated key with the above command


[email protected] #can be anything
SMTP_HOST_ADDR=smtp.google.com #gmail, zoho, whatever you use
[email protected] #smtp username
SMTP_USER_PWD=smptProviderPassword123 #smpt password
SMTP_RETRIES=3

Run Docker compose to create the containers:

docker-compose up -d

Allow public traffic to ports 80 and 443 (HTTP and HTTPS) using the “Nginx Full” UFW application profile:

sudo ufw allow "Nginx Full"

Add the plausible config into nginx proxy by replacing the your_domain_here with your domain into /etc/nginx/sites-available/plausible.conf

sudo vi /etc/nginx/sites-available/plausible.conf

In here we set up Nginx to listen on port 80 and forward the request that is coming to your_domain_here to localhost and port 8000 where Nginx is installed.

server {
    listen       80;
    listen       [::]:80;
    server_name  your_domain_here;

    access_log  /var/log/nginx/plausible.access.log;
    error_log   /var/log/nginx/plausible.error.log;

    location / {
      proxy_pass http://localhost:8000;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
}

Create a symbolic link into sites-enabled and activate the site, we also check that the config is OK and we reload Nginx so the settings to be applied.

sudo ln -s /etc/nginx/sites-available/plausible.conf /etc/nginx/sites-enabled/
# Check the config file
sudo nginx -t
#reload nginx so configs to be in place
sudo systemctl reload nginx

3. Direct the domain or subdomain to the new server.

You just need to go into the hosting provider and just put the A record as this server IP. This can vary in function of the provider where you are hosting your domain. You just need to go to DNS settings and add an A record to your VPS server IP.

4. Create the SSL Certificate

We want to use the HTTPS on the website we have used for Plausible, Let’s Encrypt will help us with our certificate. To have a certificate you need to follow the below steps:

Install certbot

CertBot package will help us generate a certificate for our domain and also automatically make Nginx use the certificate and port 443.

sudo apt install certbot python3-certbot-nginx

Get a certificate for your domain to subdomain:

This command will generate a Let’s Encrypt certificate and will alter Nginx configuration in the file plausible.conf

After we should have a fully HTTPS website.

The command will do everything for you and activate the certificate and configs on your domain:

sudo certbot --nginx -d your_domain_here
Account registered.
Requesting a certificate for analytics.bitdoze.com
Performing the following challenges:
http-01 challenge for analytics.bitdoze.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/plausible.conf
Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/plausible.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://analytics.bitdoze.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/analytics.bitdoze.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/analytics.bitdoze.com/privkey.pem
   Your certificate will expire on 2022-06-01. To obtain a new or
   tweaked version of this certificate in the future, simply run
   certbot again with the "certonly" option. To non-interactively
   renew *all* of your certificates, run "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

Now everything is set up and we can add our first site. If the server crashes the docker containers will start automatically so you don’t need to worry about it.

5. Add Your First Website

At this point, we are finished with setting up Plausible and we just need to login to Plausible and add our first website. While adding the website you will be given the code that you need to add in the header of your website.

Become a CloudPanel Expert

This course will teach you everything you need to know about web server management, from installation to backup and security.
Leave a Reply

Your email address will not be published. Required fields are marked *