Piwik is an open-source analytics software system that can be installed on a server to view the traffic of its websites in real time. It is an excellent alternative to web-based analytics solutions like Google Analytics. This guide will teach us how to install and set up Piwik on your Ubuntu 14.04-based AKLWEB HOST Server.
Before we can move ahead, make sure that your server has all the required updates. Run the following commands in the terminal for that.
sudo apt-get update
sudo apt-get upgradeYour server needs to have the LAMP (Linux, Apache, MySQL, and PHP) stack installed for Piwik to run. Furthermore, you will need an additional PHP library for Piwik to work. Run the following command to install it.
sudo apt-get install php-gdThat marks the completion of all the steps required for Piwik to work.
Make sure you are in the user directory first.
cd /var/www/piwikGrab the latest Piwik release.
wget http://builds.piwik.org/latest.zipUnzip and move the Piwik release to the user directory.
unzip latest.zipSet up the proper file permissions for the tmp and config directories.
chmod a+w /var/www/piwik/tmp
chmod a+w /var/www/piwik/configSet up proper user permissions on the complete Piwik directory.
chown -R www-data:wwww-data /var/www/piwikTo access your Piwik page, you can either install it using your server’s IP address or you can set up a custom domain name. You can skip this process if you are comfortable accessing Piwik via the IP address. If you would like a usable URL for the stats page, then continue reading.
Let’s assume that your domain is domain.com and that you want to access Piwik at stats.domain.com. For that, you would need to set up the A record first for stats.domain.com with your DNS provider. If you don’t know how to do that, then contact the support team from where you registered your domain.
After setting up the A record, We need to bind the stats domain to the server via the virtual host feature of Apache. We will need to set up a custom vhost entry for the stats domain. Run the following commands in the terminal.
sudo nano /etc/apache2/sites-available/stats.domain.com.confAdd the following lines to the above file.
<VirtualHost *:80>
ServerAdmin admin@stats.domain.com
ServerName stats.domain.com
ServerAlias stats.domain.com
DocumentRoot /var/www/piwik/
ErrorLog /var/www/piwik/logs/error.log
CustomLog /var/www/piwik/logs/access.log combined
</VirtualHost>Replace the above email address with a working email address of yours. We would also need to create the log directory.
mkdir /var/www/piwik/logsNow that the virtual host is set up, we need to activate it with the following commands.
sudo a2ensite stats.domain.com.confRestart the Apache server for the configuration to take effect.
sudo service apache2 restartNow that we have set up Piwik, you can access it either via http://<yourserverIP>/piwik or http://stats.domain.com URL from your web browser. Follow the on-screen instructions to complete the installation. Make sure to enter the proper database user who has the permissions to create a table during the installation.