Self-Hosted Analytics Using Piwik and Dokku
Hi friend! :)
This is a guide to help you host your own analytics using piwik and dokku.
This guide is a little rough around the edges, I can’t guarantee that everything works. If it does or does not, message me! <3
Last tested with Piwik 2.14.3 and Dokku v0.3.26.
This guide assumes:
- You have a dokku setup ready to go. If not i recommend following the instructions here, or for maximum ease using the one-click Digital Ocean install.
- You have a GitHub account. if not, make one.
For reference, here are the vanilla Piwiki installation instructions.
Step 1: Fork piwik repository
Go to piwik/piwik and click on the top right “Fork” button to fork the project as your current user. Now, in your new piwik repo, click on “Settings”, then rename your repo to
Next, clone your piwik repo to your local machine with
git clone https://github.com/<your-name>/analytics.<your-dokku-domain.tld>
Add the dokku remotes
git remote add dokku dokku@<your-dokku-domain.tld>:analytics
Push to dokku!
git push dokku master
It won’t work, but soon. :p
Step 2: Install dokku plugins
Let’s install some plugins. :) To do this, login to our dokku server with
step 3. configure server
time to configure, so our analytics app has what it needs.
first make some directories on the server:
now from our local machine within our forked repo, let’s copy the global config to the server. (note: we will need to do this if we ever update our repo to match upstream updates.)
scp config/global.ini.php root@<your-dokku-domain.tld>:/var/www/analytics/config
next, change the permissions of our new directories and file.
chown -R nobody:nogroup /var/www/analytics/
then, we configure our app to use our new directories:
dokku docker-options:add analytics "-v /var/www/analytics/tmp:/app/tmp"
dokku ps:restart analytics
weee, our app should be up! browse to
you should be presented with a Piwik welcome screen.
Piwik will perform a system check to make sure all is well. here’s what i got.
next you will stumble upon a form asking for the database.
let’s create a database! on the server:
after it creates and starts a database container, let’s fetch the generated credentials so we can input them into the form.
dokku config analytics
“Database Host” is
enter the details and you’ll be on your way. wooo, analytics!
at this point everything should work, until you ever rebuild your app, in which case the database configuration might change without Piwik knowing about it. to solve this issue, edit
/var/www/analytics/config/config.ini.php and replace the corresponding lines:
sweet as. :)
another thing we can do, recommended by Immortalin, is to use the database to store session files. in
config/config.ini.php, under the [General] section (add this section if it doesn’t already exist):
session_save_handler = dbtable
again, this guide is a little rough around the edges, i can’t guarantee that everything works. if it does or does not, message me! <3