Tools

How to Install Plausible on Ubuntu 20.04

In this article, we’ll explain how to install Plausible on Ubuntu 20.04.

Plausible Analytics a simple, open-source, lightweight and privacy-friendly web analytics alternative to Google Analytics. Plausible has a free as in beer self-hosted solution. No cookies and fully compliant with GDPR, CCPA and PECR. Made and hosted in the EU

This guide will explain how to install self-hosted solution on Ubuntu 20.04 server.

Prerequisites:

Install Plausible on Ubuntu 20.04

Let’s get started with the installation process.

1. Keep the server updated

# apt update -y

# apt upgrade -y

2. Clone the hosting repo

To get started quickly, download the plausible/hosting repo as a starting point. It has everything you need to boot up your own Plausible server.

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

Change current working directory

# cd hosting

In the downloaded directory you’ll find two important files:

  • docker-compose.yml - installs and orchestrates networking between your Plausible server, Postgres database, Clickhouse database (for stats), and an SMTP server. It comes with sensible defaults that are ready to go, although you’re free to tweak the settings if you wish.
  • plausible-conf.env - configures the Plausible server itself. Full configuration options are documented here.

3. Add required configuration

First, generate a random 64-charactor secret key using following command:

# openssl rand -base64 64

Copy that key and open plausible-conf.env using your favorite editor.

# vi plausible-conf.env

We need to fill following parameters:

ADMIN_USER_EMAIL=
ADMIN_USER_NAME=
ADMIN_USER_PWD=
BASE_URL=
SECRET_KEY_BASE= [Paste the secret key we have generated]

This are the default parameters. You can add additional parameter which is you can find here.

Note: Enter BASE_URL= must start with http:// or https://

After you fill all the parameters as per your choice, save and exit.

4. Start the server

Once you’ve entered your secret key base, base url and admin credentials, you’re ready to start up the server:

# docker-compose up --detach

When you run this command for the first time, it does the following:

  • Creates a Postgres database for user data
  • Creates a Clickhouse database for stats
  • Runs migrations on both databases to prepare the schema
  • Creates an admin account (which is just a normal account with a generous 100 years of free trial)
  • Starts the server on port 80

You can now navigate to http://{hostname}:8000 and see the login screen.

Install Plausible on Ubuntu 20.04

To list the containers, use following command:

# docker-compose ps

5. Install SSL

No existing reverse proxy

Install SSL via caddy-gen based docker-compose file.

If you aren’t running an existing reverse proxy, then you can use the caddy-gen based docker-compose file. Update it to include the domain name you use for your server.

# vi reverse-proxy/docker-compose.caddy-gen.yml

replace following parameters with your domain name and email id:

virtual.host: "example.com" # change to your domain name
virtual.tls-email: "[email protected]" # change to your email

Save and exit.

Now, combine the docker-compose.caddy-gen.yml with the existing docker-compose files using follwing command:

# docker-compose -f docker-compose.yml -f reverse-proxy/docker-compose.caddy-gen.yml up --detach

Above command will install SSL on your website and start all the containers.

Finally, navigate to your browser and open https://[domain_name]

Existing reverse proxy

If you are already running a reverse proxy, then the above will not work as it will clash with the existing port bindings. You should instead use one of the available configuration files:

NGINX

If you already have NGINX running as a system service, use the configuration file in the nginx directory.

Edit the file reverse-proxy/nginx/plausible to contain the domain name you use for your server, then copy it into NGINX’s configuration folder. Enable it by creating a symlink in NGINX’s enabled sites folder. Finally use Certbot to create a TLS certificate for your site:

# cp reverse-proxy/nginx/plausible /etc/nginx/sites-available
# ln -s /etc/nginx/sites-available/plausible /etc/nginx/sites-enabled/plausible
# certbot --nginx

Traefik 2

If you already have a Traefik container running on Docker, use the docker-compose file in the traefik directory. Note that it assumes that your Traefik container is set up to support certificate generation.

Edit the file reverse-proxy/traefik/docker-compose.traefik.yml to contain the domain name you use for your server, then combine it with the existing docker-compose files:

# docker-compose -f docker-compose.yml -f reverse-proxy/traefik/docker-compose.traefik.yml up

That’s it. The installation and configuration has been completed successfully.

In this article, we have seen how to install Plausible on Ubuntu 20.04.

Related Articles