Plausible Analytics is a privacy-focused, open-source analytics software that allows you to track your website’s traffic without compromising user privacy. It serves as a lightweight alternative to Google Analytics, providing a modern-looking dashboard to view your website’s statistics. In this tutorial, we will guide you through the process of installing Plausible Analytics on a Debian 12 server using Docker. By the end of this guide, you will have a fully functional analytics system running on your own server.
Prerequisites
Before we begin, make sure you have the following prerequisites in place:
- A server running Debian 12
- A non-root user with sudo privileges
- A fully qualified domain name (FQDN) pointing to your server
- The Uncomplicated Firewall (UFW) enabled and running
Step 1: Configure Firewall
The first step is to configure the firewall to allow incoming traffic to necessary ports. By default, Debian 12 uses UFW (Uncomplicated Firewall). Check if the firewall is running:
sudo ufw status
If the firewall is inactive, enable it using the following command:
sudo ufw enable
To allow SSH, HTTP, and HTTPS traffic, run the following commands:
sudo ufw allow OpenSSH sudo ufw allow http sudo ufw allow https
Step 2: Install Git
Git is required to clone the Plausible repository. Install Git using the following command:
sudo apt install git
Verify the installation by running:
git --version
Step 3: Install Docker and Docker Compose
To run Plausible Analytics, we need to install Docker and Docker Compose. Start by adding Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker.gpg
Next, add the Docker repository to the system:
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker.gpg] https://download.docker.com/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Update the APT repository list and install Docker:
sudo apt update sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Verify if Docker is installed correctly:
docker --version
Step 4: Install Nginx
Debian 12 comes with an older version of Nginx. To install the latest version, we need to add the official Nginx repository. Import Nginx’s signing key:
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg > /dev/null
Add the repository for Nginx’s stable version:
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/debian $(lsb_release -cs) nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
Update the system repositories and install Nginx:
sudo apt update sudo apt install nginx
Verify the installation:
sudo nginx -v
Step 5: Download Plausible
Now, let’s clone the Plausible Self-Hosting GitHub repository:
git clone https://github.com/plausible/hosting
Switch to the downloaded directory:
cd hosting
Step 6: Configure Plausible
In the downloaded directory, you will find the necessary files to configure your Plausible installation. The docker-compose.yml
file contains the settings for Docker Compose to install the Plausible server and its dependencies. The plausible-conf.env
file contains environment variables that allow you to customize your installation.
To generate a secret key for securing the Plausible app, run the following command:
openssl rand -base64 64 | tr -d '\n' ; echo
Copy the generated key and open the plausible-conf.env
file for editing:
nano plausible-conf.env
Paste the secret key in front of the BASE_URL
variable, and set the value for BASE_URL
to your domain (e.g., https://plausible.example.com
). Make sure to enter the base URL with HTTPS, as we will configure SSL later. You can also change the default port number if desired:
BASE_URL=https://plausible.example.com SECRET_KEY_BASE=<your_secret_key> PORT=8000
If you want to disable user registration after installation, add the following line:
DISABLE_REGISTRATION=true
If you want users to verify their email addresses during registration, add the following line:
ENABLE_EMAIL_VERIFICATION=true
If you choose to enable email verification, you can configure your SMTP details by providing the necessary information:
MAILER_NAME=Howtforge SMTP_HOST_ADDR=email-smtp.us-west-2.amazonaws.com SMTP_HOST_PORT=587 SMTP_USER_NAME=<username> SMTP_USER_PWD=<password> SMTP_HOST_SSL_ENABLED=1 SMTP_RETRIES=2
Configure Google Search Console
To connect Plausible with Google Search Console and track search terms used to reach your site, follow these steps:
- Visit the Google API Console and sign in.
- Create a new project and give it a name.
- Enable the Google Search Console API.
- Configure the consent screen by setting the product name, support email, developer contact email, and authorized domains.
- Create credentials by selecting “OAuth Client ID” and choosing “Web Application” as the project type.
- Save your Client ID and Client Secret keys.
- Add the Client ID and Client Secret keys to the
plausible-conf.env
file:
GOOGLE_CLIENT_ID=<your_client_id> GOOGLE_CLIENT_SECRET=<your_client_secret>
Save the plausible-conf.env
file and exit the editor.
Configure Google Analytics
Plausible also supports importing data from Google Analytics. To enable this feature, follow these steps:
- Go back to the Google API Console and enable the following APIs: Google Analytics Reporting API and Google Analytics API.
Step 7: Install Plausible
To install Plausible, run the following Docker command:
docker compose up -d
This command creates a PostgreSQL database, a Clickhouse database, and performs necessary migrations. It also creates an administrator account using the details from the plausible-conf.env
file and starts the server on port 8000.
Check the status of the containers:
docker ps
You should see the Plausible Analytics container running.
Step 8: Install SSL
Before configuring Nginx as a reverse proxy, we need to set up SSL certificates for secure communication. We will use Certbot to generate free SSL certificates offered by Let’s Encrypt.
If Snapd is not installed on your system, install it:
sudo apt install snapd
Ensure that Snapd is up to date:
sudo snap install core sudo snap refresh core
Install Certbot:
sudo snap install --classic certbot
Create a symbolic link for the Certbot command:
sudo ln -s /snap/bin/certbot /usr/bin/certbot
Generate an SSL certificate for your domain:
sudo certbot certonly --nginx --agree-tos --no-eff-email --staple-ocsp --preferred-challenges http -m test@shapehost.com -d plausible.example.com
This command will download the certificate to the /etc/letsencrypt/live/plausible.example.com
directory.
Generate a Diffie-Hellman group certificate:
sudo openssl dhparam-dsaparam -out /etc/ssl/certs/dhparam.pem 4096
Check the Certbot renewal scheduler service:
sudo systemctl list-timers
You should see the snap.certbot.renew.service
in the list.
Do a dry run of the SSL renewal process to ensure it works correctly:
sudo certbot renew --dry-run
If there are no errors, your certificates will renew automatically.
Step 9: Configure Nginx as a Reverse Proxy
Now, let’s configure Nginx as a reverse proxy to serve Plausible Analytics using SSL.
Create a configuration file for Plausible in the /etc/nginx/conf.d/
directory:
sudo nano /etc/nginx/conf.d/plausible.conf
Paste the following code into the file:
server { listen 80; listen [::]:80; server_name plausible.example.com; return 301 https://$host$request_uri; } server { server_name plausible.example.com; listen 443 ssl http2; listen [::]:443 ssl http2; access_log /var/log/nginx/plausible.access.log; error_log /var/log/nginx/plausible.error.log; ssl_certificate /etc/letsencrypt/live/plausible.example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/plausible.example.com/privkey.pem; ssl_trusted_certificate /etc/letsencrypt/live/plausible.example.com/chain.pem; ssl_session_timeout 1d; ssl_session_cache shared:MozSSL:10m; ssl_session_tickets off; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305; ssl_prefer_server_ciphers off; ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1; ssl_stapling on; ssl_stapling_verify on; resolver 8.8.8.8; ssl_dhparam /etc/ssl/certs/dhparam.pem; location / { proxy_pass http://127.0.0.1:8000; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
Save the file and exit the editor.
Open the Nginx configuration file for editing:
sudo nano /etc/nginx/nginx.conf
Add the following line before the include /etc/nginx/conf.d/*.conf;
line:
server_names_hash_bucket_size 64;
Save the file and exit the editor.
Verify the Nginx configuration file syntax:
sudo nginx -t
If there are no syntax errors, restart the Nginx service:
sudo systemctl restart nginx
Step 10: Add Site and Start Tracking
Now that Plausible Analytics is set up, let’s add your website and start tracking its statistics.
Open your browser and visit https://plausible.example.com
. You should see the Plausible registration screen. Click the “Create my account” button to proceed.
If you have enabled email verification, you will be asked to enter a verification code sent to your email. If you haven’t received the email, run the following command to verify all users in the database:
docker compose exec plausible_db psql -U postgres -d plausible_db -c "UPDATE users SET email_verified = true;"
Next, you will be prompted to add a site. Enter the domain you want to track and select the timezone for stats reporting.
On the next page, you will be provided with the JavaScript tracking code. Copy the code and paste it between the <head>
tags of your website. Click the “Start collecting data” button to proceed.
Depending on your website’s traffic, the Plausible Analytics dashboard will start displaying statistics for your website.
Conclusion
Congratulations! You have successfully installed and configured Plausible Analytics on your Debian 12 server. Now you have complete control over your website’s analytics without compromising user privacy. If you have any questions or run into any issues, feel free to post them in the comments below. Enjoy monitoring your website’s performance with Plausible Analytics!
If you’re looking for reliable and scalable cloud hosting solutions, Shape.host provides Linux SSD VPS services that can meet your needs. With Shape.host, you can focus on your business while leaving the hosting infrastructure in capable hands. Visit Shape.host for more information and to explore their hosting options.