2.54 KB
Newer Older
Dave Lane's avatar
Dave Lane committed
1 2
# Matomo Docker Recipe

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
A quick recipe for firing up a Matomo instance (formerly Piwik) via Docker Compose. 

## Setup

The way we set up things for the OER Foundation, is that we tend to use Docker Compose to host containers on a virtual server. We usually run MariaDB on the Docker host rather than as a container, as it makes database backups easier, especially when we have lots of services that depend on MariaDB. 

We usually put our Docker Compose configurations under /home/docker, in a directory with the domain name of the service. In this case, it's /home/docker/ In that directory, we often only have a docker-compose.yml file. It's where all Docker Compose commands are issued.

We store site-related data in /home/data - in this case in /home/data/ The source code for Matomo is in /home/data/ We also usually have /home/data/ for the generic NGINX configuration for the service (the files we use are held in the `nginx` director in this repo). We use another NGINX instance running on the host as a reverse proxy and as the endpoint for SSL (HTTPS). That simplifies maintenance of the Let's Encrypt certificates we use. 

The only things you need to change are the [sitename] (we use the domain name of the site there) and the port you make the nginx instance visible on - if it's free, you can use 8080. Make sure the port specified in `docker-compose.yml` (create it from our sample via `cp docker-compose.yml-sample docker-compose.yml` in the git directory. 

You can create a suitable database in your MariaDB with the following (you should be able to access the MariaDB command line via `sudo mysql` on any current Ubuntu Linux server) - just add your own password for [password]:

CREATE DATABASE matomo CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER "matomo"@"%" IDENTIFIED BY "[password]";
GRANT ALL ON matomo.* TO "matomo"@"%";

Note that your database will be available on from the perspective of your Docker containers.

You will also need to use the files in `reverse-proxy` (copy the include file to the right place: `sudo cp -a includes/letsencrypt.conf to /etc/nginx/` - and we would normally rename the matomo file to /etc/nginx/sites-available/[sitename], replacing the nginx port (if not 8080) and the [sitename] and then run `sudo ln -sf /etc/nginx/sites-available/[sitename] /etc/nginx/site-enabled` and then run `sudo nginx -t` to make sure there aren't any syntax errors, and finally `sudo service nginx reload` to restart the server.