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 http://piwik.org/

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:

<?php

phpinfo();

?>

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

sudo apt-get install php5-gd

Then:

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

Advertisements

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: http://tuckey.org/urlrewrite/

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

<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

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

<rule>
<from>^(.+)/(.+)/$</from>
<to type=”redirect”>$1/$2</to>
</rule>

This may not be a perfect solution but it works 🙂