Matomo Analytics & Ghost
Why self host?
Partly because I can, and also because I'm a small-time believer in if I can do it myself and not rely on a company to do it for me, why wouldn't I?
Why Ghost and not WordPress?
Whilst WordPress is clearly a very good platform, its majorly overkill and overly complex in usage for what I wanted - a simple blog platform.
Ghost fits the bill nicely as its simple to setup, easy to use, and very easy to get looking nice.
Why Matomo and not Google Analytics?
Matomo is an self-hostable Google Analytics alternative, which in layman's terms means I can see website stats for this website, that runs off the Ghost platform.
I don't have anything against Google Analytics, but I like to self-host where possible.
One good thing about Matomo, is the default setup helps meet GDPR compliance around data collection, along with giving more settings to go the nth degree with it if wanted.
Pre-Requisites
- You already have Ghost up and running, with an external address
- You are running Unraid as your host OS.
- You have a running Nginx Proxy Manager container: Guide
Setting up MariaDB
First, we need to setup the database.
Go to the community applications menu in Unraid (Apps).
In the search box on the right, type in "MariaDB", and select the one listed as using the 'linuxserver' repository. Click the download icon (bottom left)
You will be taken the the container setup screen.
Here, you will enter details that will go into the docker template, where it will set some base options for MariaDB.
Most of these you can leave at default, however the ones to pay attention too -
What | Note |
---|---|
Name | I would recommend renaming this to something more descriptive, as a lot of containers use MariaDb as their backend. Planning a naming convention in advance, will save some headaches in future. I would recommend something like mariadb_appname. In this case, mariadb_matomo |
Host Port | Similar to name. If its your first MariaDb container, leaving it at default is fine. After that, you'll need to use different ports for any additional databases. |
AppData Config Path | Similar to name, I would recommend setting this up with a naming convention. I would also recommend matching the naming convention with the container name for consistancy purposes. |
"Key 3"
If it doesn't exist already, I would recommend adding the environment variable for 'MYSQL_ROOT_PASSWORD' - whilst I'm sure there are better ways to achieve this, having an instance startup without a password on its root account isn't something I'm comfortable with.
To add a custom variable, click the link at the bottom that says "+ Add another Path, Port, Variable, Label or Device".
Change the dropdown to 'Variable' and then enter the name (your choice), Key and Default value.
AppData Config Path
Similar to name, I would recommend setting this up with a naming convention. I would also recommend matching the naming convention with the container name for consistency purposes.
Once these are filled out, click 'DONE' at the bottom and the container image will download and setup based on your variables above.
You can check its running on the docker tab of Unraid.
Here we can see the container is both running, its network and port mappings, and the paths for its appdata.
Setting up a user & database in MariaDB
We now need to create the database backend for Matomo to use.
The following steps can be used for any app that uses MariaDB, not just Matomo.
From the Unraid Docker Tab, click the icon for MariaDB_Matomo, and in the drop down, select 'Console'.
You should get a popup black window with a single '#' in the top left. This is a basic bash shell session running against just the container. From this, we can run commands specifically for this container.
First, we need to create a user in MariaDB for Matomo to use. Type into the window -
mysql -u root -p
This tells mysql (MariaDB) to login as root, and ask for a password. Enter the password you added during the container setup, and press enter. You should now be dropped into the MariaDB CLI.
We now need to enter a series of commands to create a database and user -
create database [DatabaseName];
grant all privileges on [DatabaseName].* TO '[Username]'@'%' identified by '[Password]';
flush privileges;
After this, you now have both a database and user to use with Matomo during setup.
Type 'exit', press enter, and then a second time to close the console window.
MariaDb - Max Packet Size
The next part of the setup involves modifying a single variable in MariaDb, specifically for Matomo's purpose. Most other apps won't need this variable.
The easiest way to do this is to use the inbuilt terminal window in Unraid, or SSH via your own terminal window.
Once logged in, browse to the appdata folder for your MariaDB. Assuming standard paths for Unraid -
cd /mnt/user/appdata/ContainerName
From here, we need to edit the custom.cnf file to adjust the max packet size variable. Run the following command to edit the file with nano.
nano ./custom.cnf
Browse down to the [mysqld]
section and change the variable for max_allowed_packet
from 16
to 64
.
Once done, press CTRL+O
to save the file, then CTRL+X
to exit.
Finally, type 'exit' into the terminal window to close it out, and then go to the docker tab, find the MariaDB container, click its icon, and restart it.
Configure Nginx Proxy Manager
Following the guide here, use the following details to setup NPM for usage with Matomo.
Details
What | Note |
---|---|
Domain Names | Enter the sub-domain you have pointed at your home network |
Scheme | http |
Forward Hostname/IP | IP Address of your site/service |
Forward Port | 8383 - Or a custom port for the WebUI on Matomo |
Block Common Exploits | Enable |
SSL
What | Note |
---|---|
SSL Certificate | Request a new certificate |
Force SSL | Enabled |
HTTP/2 Support | Enabled |
HSTS Enabled | Enabled |
HSTS Subdomains | Disabled |
Then press 'save' and accept the LetsEncrypt notice/warning.
Setting up the Matomo container
Next, we need to setup Matomo.
Go to the community applications menu in Unraid (Apps).
In the search box on the right, type in "Matomo", and select the one listed as using the 'Sycotix' repository. Click the download icon (bottom left)
You will be taken the the container setup screen.
Here, you will enter details that will go into the docker template, where it will set some base options for Matomo.
Unlike MariaDB, most of these you will be editing -
What | Note |
---|---|
Name | Unless you plan on multiple Matomo instances, the default should suffice |
WebUI | Leave as default (recommended) or customise to your own port requirements |
MATOMO_DATABASE_HOST | IP of your Unraid server |
MATOMO_DATABASE_PORT | Port you configured during the MariaDB setup |
MATOMO_DATABASE_USERNAME | Username you setup within MariaDB |
MATOMO_DATABASE_PASSWORD | Password you setup within MariaDB |
MATOMO_DATABASE_DBNAME | Database Name you setup within MariaDB |
MATOMO_SERVER_NAME | Planned external DNS name |
AppData Config Path | I recommend matching the naming convention with the container name for consistancy purposes. |
Click 'DONE' at the bottom and the container image will download and setup based on your variables above.
You can check its running on the docker tab of Unraid.
Here we can see the container is both running, its network and port mappings, and the paths for its appdata.
Setting up Matomo
Next, we need to setup Matomo itself.
Go to your custom domain name that you have set for Matomo, for example, matomo.domain.com
Its very important you do not use the internal LAN address to initially access/setup Matomo!
This is due to how the app configures its trusted hosts and external addresses for use in code inserts. Accessing and configuring through the WebGUI, from the intended external address will ensure that this is setup correctly the first time.
Assuming everything's worked, you'll see the setup welcome screen.
This section is relatively straight forward - just follow the steps.
For additional context, I'll demonstrate a few of the sections.
System Check - this is where Matomo will check everything is as expected/needed for a successful installation.
Enter details for your database based on your setup of MariaDB.
For database server, enter your Unraid IP address, with :port on the end.
For example: 192.168.1.1:3308
Table prefix you can leave as default.
This section is hit and miss.
Sometimes you get what's in the screenshot, and sometimes it complains about an existing database/table.
In that scenario, just select the option to 'delete' the existing tables/database and the wizard will continue as normal.
This is for you to enter your main administrative account for the application, be sure to pick a complex password, as this site will be externally facing.
Here is where you will enter the details for your Ghost website - It's as simple as entering the URL, time zone and a name that its referenced by in Matomo's dashboard.
On this screen you get the tracking code for usage in ghost.
Copy and paste the entire block to a temporary place, such as notepad.
You're now done.
Only possible extra step is once you click 'continue to matomo', sometimes it will prompt for an update.
When this occurs follow the steps and leave the page running. It can sometimes take a long time, even on a fast server.
Often, the page will timeout, in that case, just leave Matomo alone for 10-15mins and come back to it later. This will give it time to complete the database updates.
More information on this process, here.
Getting accurate GeoIP Results
There's no point me reinventing the wheel, the Matomo guides themselves are great for elaborating on this aspect -
Other notes
Configuring Ghost
Go to your Ghost Admin panel (https://www.website.com/ghost).
Click 'Code Injection' on the lower left.
Paste the tracking code from the Matomo wizard in the 'Site Header' section, then click 'Save'.
You are now done configuring Ghost & Matomo.
Over the next day or so, you should start to see your charts within Matomo fill with data, mostly bots, but hopefully over time, more users!
![]() | ![]() |