I decided to self-host my website analytics. In this blog, I will walk you through the process of self-hosting Plausible analytics and explain why I made this decision.
Why Self-Host?
The cost and control are the two main factors that motivated me to self-host Plausible analytics. Hosted solutions can be quite expensive when you have a significant number of pageviews. By self-hosting, I am able to save on costs and have full control over my analytics data.
Getting Started
To get started, you will need a DigitalOcean account. If you don’t have one yet, you can use my referral link to get $200 in free credits for the next 60 days. Once you have created an account, you can proceed with the following steps:
- Create a new project on DigitalOcean.
- Click on “New Project” in the sidebar and give it a name.
- Choose a region for your Droplet (VPS) that is closest to your users.
- Select an image (I recommend using Docker for easy self-hosting).
- Choose a size for your Droplet (I recommend the $4/m plan, if available).
- Set up authentication method (password auth is fine for this tutorial).
- Create your Droplet.
- Set up DNS to point a subdomain of your domain to the Droplet’s IP address.
Configuring Plausible Analytics
Now that your Droplet is up and running, you can proceed with configuring Plausible analytics:
- Access the Droplet’s console.
- Clone the Plausible Docker Compose setup to the
/opt
folder. - Update the
plausible-conf.env
file with your desired configuration (e.g., BASE_URL, SECRET_KEY_BASE). - Update the
docker-compose.yml
file to specify the localhost port for Plausible (e.g.,ports: - 127.0.0.1:8000:8000
). - Start the Plausible analytics Docker containers using
docker-compose up -d
.
Setting Up Nginx
To enable secure connections and set up a reverse proxy for Plausible analytics, follow these steps:
- Install and configure Nginx on your Droplet.
- Create a
plausible.conf
file in/etc/nginx/sites-available/
and configure it to proxy requests to Plausible. - Enable the Nginx site by creating a symbolic link in
/etc/nginx/sites-enabled/
. - Test the Nginx configuration and reload Nginx.
- Obtain and configure SSL certificates using Certbot.
- Verify that Plausible analytics is working by accessing your Plausible URL.
Disabling Registration
By default, anyone can create an account on your self-hosted Plausible instance. To disable registration, follow these steps:
- Open the
plausible-conf.env
file and add the lineDISABLE_REGISTRATION=true
. - Reload Plausible using the commands
docker-compose down --remove-orphans
anddocker-compose up -d
.
That’s it! You have successfully self-hosted Plausible analytics and disabled registration to maintain control over who can access your analytics data.
I hope this tutorial has been helpful in guiding you through the process of self-hosting Plausible analytics. Plausible is a great tool for website analytics, and by self-hosting, you can enjoy its benefits while saving on costs. Don’t forget to support the Plausible project by becoming a sponsor.
Tags: self-hosting, Plausible analytics, website analytics, Docker, Nginx, SSL certificates