How to Install GoatCounter on Debian Latest?

GoatCounter is an open-source web analytics software that keeps track of website traffic in real-time. This guide will walk you through the steps to install GoatCounter on a Debian latest system.

Prerequisites

  • A Debian latest server with root access or user with sudo privileges.
  • A domain name and SSL certificate if you want to access GoatCounter over HTTPS.
  • A PostgreSQL database.

Step 1: Install Dependencies

Before installing GoatCounter, you need to install the following dependencies on your Debian server:

sudo apt-get update
sudo apt-get install -y libpq-dev postgresql wget curl

Step 2: Download and Extract GoatCounter

Go to the GoatCounter download page and copy the download link for your Debian architecture. Then, run the following command to download and extract GoatCounter:

wget https://github.com/goatcounter/goatcounter/releases/download/v1.3.1/goatcounter-v1.3.1-linux-amd64.tar.gz
tar xvf goatcounter-v1.3.1-linux-amd64.tar.gz

Step 3: Configure GoatCounter

Next, navigate to the extracted folder and create a configuration file:

cd goatcounter-v1.3.1-linux-amd64
cp example.site.conf site.conf

Edit the site.conf file with your PostgreSQL database credentials:

goatcounter_db = "postgresql://user:password@localhost:port/dbname"

You can also customize other settings, such as the website domain and name.

Step 4: Start GoatCounter

To start GoatCounter, run the following command:

./goatcounter run

By default, GoatCounter listens on port 8080. You can access GoatCounter by navigating to your server’s IP address or domain name followed by :8080.

Optional: Configure HTTPS

To use HTTPS, you need to configure a reverse proxy for GoatCounter. For example, you can use Nginx or Apache. Here’s an example of how to configure Nginx for HTTPS:

  1. Install Nginx:

    sudo apt-get install -y nginx
    
  2. Create an Nginx server block for GoatCounter:

    sudo nano /etc/nginx/sites-available/goatcounter
    

    Add the following configuration:

    server {
        listen 80;
        server_name domain.com;
    
        location / {
            return 301 https://$server_name$request_uri;
        }
    }
    
    server {
        listen 443 ssl;
        server_name domain.com;
    
        ssl_certificate /path/to/ssl/cert;
        ssl_certificate_key /path/to/ssl/key;
    
        location / {
            proxy_pass http://localhost:8080;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto https;
            proxy_redirect off;
            # ... other proxy settings
        }
    }
    
    • Replace domain.com, /path/to/ssl/cert, and /path/to/ssl/key with your domain name and SSL certificate file paths.
    • The proxy_pass directive sets the reverse proxy destination to localhost:8080, where GoatCounter is listening.
    • Save and close the file.
  3. Enable the GoatCounter server block:

    sudo ln -s /etc/nginx/sites-available/goatcounter /etc/nginx/sites-enabled/
    sudo nginx -t
    sudo systemctl reload nginx
    

You can now access GoatCounter over HTTPS by navigating to your domain name.

Congratulations, you have successfully installed and configured GoatCounter on Debian latest.