How to Install Plausible Analytics on Debian 11
Plausible Analytics is a free, open-source, self-hosted web traffic measuring application that allows you to track website visitors and sessions within a single web dashboard. It is lightweight, privacy-focused, simple to use, and works by adding a single line of code in your website's head section.
In this article, you will learn how to install Plausible Analytics on a Debian 11 server.
Prerequisites
- Deploy a Debian 11 server on Vultr.
- Point a subdomain to the server.
- Access the Server with SSH.
- Install Docker and Docker Compose.
- Install Nginx.
Installation
Clone the Plausible Analytics GitHub repository to a new directory named plausible
.
$ sudo git clone https://github.com/plausible/hosting plausible
Move the files to a system-wide directory like /usr/local
.
$ sudo mv plausible/ /usr/local
Switch to the files directory.
$ cd plausible/
Then, use OpenSSL
to generate a new random secret key.
$ openssl rand -base64 64 | tr -d '\n' ; echo
The command will output a 64 character key. Copy it to your clipboard.
Next, open and edit the file plausible-conf.env
.
$ sudo nano plausible-conf.env
Below are the file placeholder entries:
ADMIN_USER_EMAIL=replace-me
ADMIN_USER_NAME=replace-me
ADMIN_USER_PWD=replace-me
BASE_URL=replace-me
SECRET_KEY_BASE=replace-me
Replace them with your administrator username, strong 8-character password, and the generated secret key to set up Plausible.
Save and close the file.
Now, use docker-compose to download and configure necessary dependencies for the Plausible Analytics container.
$ sudo $ docker-compose up -d
The above command will create new Postgres and ClickHouse databases for user data, statistics respectively. Then, set up the administrator account, and start Plausible on port 8000
.
Configure Nginx as a Reverse Proxy
Create a new Nginx configuration file.
$ sudo nano /etc/nginx/conf.d/analytics.conf
Paste the following contents to the file, replacing analytics.example.com
with your actual subdomain.
server {
listen 80;
listen [::]:80;
server_name analytics.example.com;
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;
}
}
Save and close the file.
Test Nginx for any configuration errors.
$ sudo nginx -t
Output:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Restart Nginx.
$ sudo service nginx restart
Configure Firewall
Allow HTTP Traffic.
$ sudo ufw allow 80/tcp
Allow HTTPS Traffic on port 443.
$ sudo ufw allow 443/tcp
Reload Firewall to enable the new rules.
$ sudo ufw reload
Install SSL Certificates
Install Certbot if not already installed.
$ sudo apt install certbot python3-certbot-nginx
Then, run the following command replacing analytics.example.com
, user@example.com
with your actual subdomain and email address, respectively.
$ sudo certbot -d analytics.example.com -m user@example.com --agree-tos
If your subdomain is pointed to the server, an SSL certificate will be installed, and the Nginx configuration file will be modified with the new settings.
Login to Your Plausible Analytics Server
You have successfully installed and configured Plausible Analytics to run on your server. Test the installation by visiting your subdomain.
https://analytics.example.com
Log in with the administrator username and password set earlier. Once successful, click Add Site
, then copy the listed tracking code, and paste it in your website <head> </head>
section.
In case of any runtime errors, view the Plausible container logs from your terminal window using the following command:
$ docker logs plausible_plausible_1
If there are no errors, your output should be similar to:
Loading plausible..
Starting dependencies..
Starting repos..
create Plausible.Repo database if it doesn't exist
create Plausible.ClickhouseRepo database if it doesn't exist
Creation of Db successful!
Loading plausible..
Starting dependencies..
Starting repos..
Running migrations for Elixir.Plausible.Repo
Running migrations for Elixir.Plausible.ClickhouseRepo
Migrations successful!
Loading plausible..
Starting dependencies..
Starting repos..
Admin user created successful!
Congratulations, you have successfully installed Plausible Analytics on a Debian 11 server, you can add multiple websites and securely track them through the Plausible backend dashboard. To receive analytics reports via email, verify that port 25 is open on your server.