How to setup piwik - Open Source Web Analytics

In this article we are going to learn How to setup Piwik under Linux / UNIX environments.

Note: In this article we are using Debian based operating system Ubuntu 12.04 LTS.

This works under Ubuntu 10.04 LTS, Ubuntu 13, Debian 6 and Debian 7.

What is Piwik?

Wait, wait, wait. Before we get started, what is Piwik anyway? Piwik is a downloadable open-source web analytics system, which can be locally installed on your server / machine. It has more personalized solution to services like Google Analytics but Google Analytics does not let us keep ownership and full control over the data.

Piwik lets you have ownership and more control of your data. It also shows you detailed traffic information in real-time, and it has more stylistic and in depth graphs which can help you to visualize data more effectively.

You either need to run commands as root and ignore sudo in the below commands. or if you are logged in with your user it should be a sudo user.

sudo apt-get update

sudo apt-get -y upgrade

The first command is updating software update repositories and second command is upgrading software packages installed against the updated repositories. This is generally good practice before installing a new application or subsystem on your server.

Piwik requires a basic LAMP setup (Linux, Apache, MySQL and PHP).

This will also work on distributions like CentOS and RHEL if you already have LAMP setup up and running.

If you are a Redhat / RHEL / CentOS user you can use easily “XAMPP” which is a bundle of LAMP and has everything in it.

Since as of this article we are using Ubuntu 12.04 LTS, we can easily install LAMP using one simple command that lets you perform an automated install of many services.

To install LAMP (Linux, Apache, MySQL and PHP) use one automated command:

sudo tasksel

It will open a menu and ask you to select the services that you want to install. Use the down arrow to go to the option saying “LAMP Server” and select the option by pressing the spacebar key. Then, use the TAB key to choose the OK button to start the process of install LAMP.

During the process if it asks you for the options just select “the default option” and “keep the local version currently installed”.

It will ask you for the MySQL root password. Keep this in a safe place, as you will need this later.

After the installation is completed we need to install two additional packages that will be required for the proper function of the Piwik software.

You can install the two required packages by using the below command:

apt-get install unzip php5-gd

At this stage you have a LAMP server up and running with all dependencies fulfilled.

Go to the default directory of the Apache web server using the below command:

You need to have “wget” installed. It is usually installed by default; just in case if you don’t have it installed, you can install it first using the command:

sudo apt-get install wget

Now on to getting piwik

wget http://builds.piwik.org/latest.zip

Delete any existing files that may be present in the Apache’s default DocumentRoot “/var/www/” by using below command:

(note: only perform the following command on a new server without an existing website. If you are installing piwik on a live production web server with existing websites, choose an appropriate location to place piwik and do not use the follow rm command on DocumentRoot.)

rm *html

Extract the zip archive by using below command:

unzip latest.zip

Now set the correct ownership for the directory just extracted called “piwik”

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

Finally, restart the Apache web server

sudo /etc/init.d/apache2 restart

Or

sudo service apache2 restart

You can now proceed for the rest of the installation using the Web based installer of “Piwik”

Open your web browser and navigate to the server IP address or domain name configured.

http://192.168.10.20/piwik

You should see the welcome screen of Piwik; then, click Next to proceed further.

All checks for the System should be green to proceed further and we are now at the Database setup configuration page.

Enter as below:

Database server = 127.0.0.1

Login = root

Password = which you had set during the LAMP installation

Database name = piwik (it could be anything you like as well)

Table prefix = piwik_ (you may change to something else as well)

Adapter = PDO_MYSQL

Then click next to proceed, if you entered all details as above correctly it will proceed and create a new database. It will use the database name and create tables using the prefix you defined.

At the Super User screen, we set our username login and password for logging into the Piwik web analytics system.

Then write the email address and email preferences settings and click NEXT when we are finish entering all details.

Next you will see we are at the “Setup a website” screen

This asks us for website name, website URL, website time zone and asks whether this is an ecommerce website or not.

The following are your choices:

Website name = Example Analytics Site

Website URL = http://example.com or IP address if you don’t have the domain

Website time zone = CEST (Central European Time)

Next, you will see the screen “Tracking code for Example Analytics Site”

Copy the code generated and put it in your website’s footer before the closing footer tags. This is required to give telemetry back to piwik.

If you are using Wordpress, Joomla, or any other CMS, you make want to utilize Piwik’s plugin. If there are no plugins available for the CMS which you are using you need to edit your template file and insert the code in your footer.

Congratulations! You have now a fully setup and configured installation of Piwik Analytics.

You can now ccess Piwik’s interface using below URL:

http://example.com/piwik

Or if you choose, an IP address

http://192.168.10.20/piwik

It will come up with a login page asking for your username and password.

You need to enter the username and password which you choose during the installation.

This article has been provided by Codero Hosting, the leading provider of reliable dedicated, managed and cloud hosting services. Need more information on this topic or to learn more about Codero’s hosting services please visit www.codero.com, chat with us online or give us a call at 866-2-CODERO.