how to install plausible analytics on ubuntu

How To Install Plausible Analytics on Ubuntu 22.04

Spread the love

Plausible Analytics is a free and open-source, self-hosted web analytics application that helps you to track your website visitors. It is a simple analytics alternative to Google Analytics.

In this tutorial, we will install Plausible in a docker container and then install Apache as a reverse proxy for Plausible Analytics.

Prerequisites

  • An Ubuntu 22.04 VPS
  • Full SSH root access or a user with sudo privileges is required

Step 1. Log in to the server and update

Login to your Ubuntu 22.04 VPS via SSH. In this article, we will use ‘root’ to run the shell commands.

If you want to use your regular system user with sudo privileges to run the commands, make sure to append ‘sudo’ in front of the commands.

# ssh root@IP_Address -p Port_Number

You need to replace “IP_Address” and “Port_number” with your server’s IP address and SSH port number.

We can run these commands to ensure that all installed packages are up to date.

# apt update
# apt upgrade

Step 2. Install Docker CE and Docker Compose

By default, the latest Docker CE package is not available in the Ubuntu 22.04 default repository, so you will need to add the Docker CE official repository to your server.

Use the following command to install the dependencies or pre-requisite packages.

# apt-get install git apt-transport-https ca-certificates curl software-properties-common -y

Then, add the GPG key and repository with the following commands:

# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/docker-archive-keyring.gpg
# add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Now you can install Docker and Docker Compose with the following command:

# apt update
# apt-get install docker-ce docker-compose

Verify the Docker version with the following command:

# docker --version

Output:

Docker version 20.10.21, build baeda1f

Step 3. Download Plausible

Next, you need to clone the Plausible repository from the GitHub repository. To do this, go to the /opt directory with the following command:

# cd /opt

Then, you can download it with the following command:

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

Now move into the new directory that you have created:

# cd plausible

Generate a secrete password with the following command:

# openssl rand 64 | base64 -w 0 ; echo

This command will create 64 random characters:

VSqCkxxFh0lQAcKgM+NmLzya28kbAr++FBL8b6qUxtAi9AeGScacv+fSGfYBqHiAVevv3H70qIJML1MabF+Klg==

Copy them, then open the Plausible configuration file with your favorite text editor:

# nano plausible-conf.env

The file contains five variables that you’ll need to fill in:

[email protected]
ADMIN_USER_NAME=admin
ADMIN_USER_PWD=Str0ng_Passw0rd
BASE_URL=https://plausible.your-domain.com
SECRET_KEY_BASE=VSqCkxxFh0lQAcKgM+NmLzya28kbAr++FBL8b6qUxtAi9AeGScacv+fSGfYBqHiAVevv3H70qIJML1MabF+Klg==

Note:  The password you define here must be at least 6 characters.

Now you need to update the docker-compose.yml file. Open the file with the following command:

# nano docker-compose.yml

Find the Plausible section in the file and search for the ports, and update it to the following:

ports:
- 127.0.0.1:8000:8000

Then use the following command to download, configure, and launch the containers:

# docker-compose up --detach

This ensures that Plausible only listens on the localhost interface and is not publicly available.

Plausible Analytics has been installed and is now running on port 8000.

Step 4. Install Apache Web Server and Create Apache Virtual Host File

To install the Apache web server execute the command below:

# apt install apache2

Once installed, start and enable the service.

# systemctl enable apache2 && systemctl start apache2

Check if the service is up and running:

# systemctl status apache2

Enable the proxy and proxy_http modules in Apache using the following commands:

# a2enmod proxy
# a2enmod proxy_http

To access Plausible Analytics via domain name, we need to create Apache Virtual Host file.

First, create the configuration file with the following command:

# nano /etc/apache2/sites-available/plausible.conf

Open the file, and paste the following lines of code:

<VirtualHost *:80>
     ServerAdmin admin@your_domain.com
     ServerName plausible.your-domain.com

     ErrorLog ${APACHE_LOG_DIR}/plausible.your-domain_error.log
     CustomLog ${APACHE_LOG_DIR}/plausible.your-domain_access.log combined

        ProxyPreserveHost On
        ProxyPass / http://127.0.0.1:8000/
        ProxyPassReverse / http://127.0.0.1:8000/

</VirtualHost>

Enable the Apache2 configuration file and other modules:

# a2ensite plausible.conf

Check the syntax of the Apache2 configuration.

# apachectl -t

You should receive the following output:

root@host:~# apachectl -t
Syntax OK

If you receive this output, you can safely restart the Apache service.

# systemctl restart apache2

Step 5. Install an SSL Certificate

This step will show you how to install an SSL certificate for your Plausible website using the free one from Let’s Encrypt.

Install the required packages by running the following command:

# apt install python3-certbot-apache

Then run this command to install a new SSL certificate for your domain name:

# certbot --apache -d plausible.your-domain.com

Please select ‘2’ and choose to redirect HTTP traffic to HTTPS. It will update your Plausible Apache virtual host file to redirect all HTTP traffic to HTTPS.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

You should now be able to access your Plausible Analytics at https://plausible.your-domain.com

Plausible Analytics

If you are one of our web hosting clients and use our managed Ubuntu Hosting, you don’t have to follow this tutorial and install Plausible Analytics on your Ubuntu 22.04 server yourself. You can simply ask our expert Linux hosting admins to set all of these up for you quickly and easily.  They are available 24×7 and will respond to your request immediately.

PS. If you liked this post, please share it with your friends on social networks using the buttons below, or simply leave a comment in the comments section. Thank you.

Leave a Reply

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