How to install Piwik Statistics System

Today I’m going to write about how to install Piwik Statistics System. This is an opensource web analytic, an alternative to Google analytic. A website for Piwik is

Firstly, I downloaded the zip file from the above website and unziped it.

Then I checked if my server has PDO installed by looking at php info. This can be done by creating an empty page with this code:




Another requirement is the GD image library. To enable this, open a terminal and type:

sudo apt-get install php5-gd


sudo /etc/init.d/apache restart

The next requirement is to have a memory of 128M. This can be done by editing the php.ini file under /etc/php5/apache2

sudo vi /etc/php5/apache2/php.init

Change memory limit to:

memory_limit = 128M

and restart the server with:

sudo /etc/apache2 restart

Copied piwik folder to the webserver directory.

Once that’s done, I went to http://localhost/piwik/ and followed the install instruction.

If it asked for chmod, it could mean that apache cannot write to this directory. There are 2 solutions to this problem.

1. To perform a change mode to 777, which allows everyone to be able to read, write and execute to that folder (possibly including subfolders.) !!!This is NOT recommended!!!

sudo chmod -R 777 /var/www/piwik

2. To change the owner of the folder to apache user. A default apache user is www-data. This is a lot better solution:

sudo chown -R www-data:www-data /var/www/piwik


Rewrite url for webapp, similar to htaccess

Webapp doesn’t seem to support htaccess file. Therefore, url rewrite can be done by using UrlRewriteFilter. It can be downloaded from:

This package is very easy to install:

1. Download the package

2. Put the library in to lib folder under WEB-INF or add as dependencies through maven

3. Put the filter to web.xml in WEB-INF


4. Copy and Edit urlrewrite.xml to create the rule.

I used this UrlRewriteFilter to take the trailing slashes off the url

For example:

From http://abc.def/ghi/jkl

To http://abc.def/ghi/jkl

What I did was:

1. Tell UrlRewrite to use context path

<urlrewrite use-context=”true”>

2. Add this rule

<to type=”redirect”>$1/$2</to>

This may not be a perfect solution but it works 🙂