Replace Google Analytics with Piwik on OpenShift

by Taylor Fausak on

I have used Google Analytics for years. Recently I’ve been interested in moving off of Google products. I researched lots of other analytics providers, but didn’t find any that I liked. Then I found Piwik.

Piwik is a free-as-in-speech web analytics platform. Its mission statement is to “liberate web analytics”. I wanted to set it up as a free-as-in-beer replacement for Google Analytics. Thanks to OpenShift, that’s possible.

To get started, clone my piwik-openshift repository.

git clone
cd piwik-openshift

I like sandboxing my apps with Vagrant, but this step is optional. If you skip it, just install rhc.

vagrant up
vagrant ssh
cd /vagrant

If you don’t have one already, create an OpenShift account. Then configure rhc to use it.

rhc setup

Next you need to create a PHP app. Piwik also requires MySQL, so add that cartridge to your app.

rhc app create piwik php-5.3
rhc cartridge add mysql-5.1 --app piwik

Creating a new app clones the initial repository for you. You don’t need it, so you can just delete it.

rm --force --recursive piwik

We’re going to use the current directory as the source for the app we just created. That means we need to add a Git remote for it. Then we need to push it to OpenShift, which will also deploy the app.

url=$(rhc app show piwik | awk '/Git URL/ { print $3 }')
git remote add rhc $url
git push --force rhc master

All that’s left to do is set up Piwik. Go to piwik-<namespace> and follow the instructions. When you get to the database setup, you’ll have to ask rhc for the values.

hostname=$(rhc app show piwik | awk '/SSH/ { print $2 }')
command='env | grep OPENSHIFT_MYSQL_DB_'
ssh $hostname $command

Here’s the environment variables you should be looking for, along with which field they map to.

  • OPENSHIFT_MYSQL_DB_HOST: database server

Finish the rest of the setup and you should be good to go! Enjoy your free analytics.