Piwik do not show statistics after installation

,

I have installed Piwik but it’s not working after installation. How to configure it ?

You have to include a javascript piece of code in the webpages you want to monitor.

I don’t remember exactly, but everything is explained in Piwik. :slight_smile:

Ok I found the javascript .

But, how to edit and add this before tag of webpages of the server ?

It depends on the app. You can do it quite easily in Wordpress via the Wordpress administration, for the other app you probably can do it manually (often by editing a template file).

Hello

If you have activated loganalytics function, piwik will check your nginx log at 4am every day. Independently to javascript code.

How to activate log-analytics function ?

By default at installation, the log-analytics script is activated. Except if you chose “no” to “Enable the analysis of server logs.”

Check the log “misc/log-analytics/lastlog_loganalytics_cron.log”, if it exists.

I did not find “misc/log-analytics/lastlog_loganalytics_cron.log”.
I have not change any option.
Please tell me how to enable log-analytics.

How to import the pages into Wordpress ? It only has the sample page.

To activate log-analytics script, you should create the cron file in /etc/cron.d/piwik_loganalytics

The content of cron file should be find here:

Replace __ FINALPATH__ by the path of piwik dir, usually /var/www/piwik

And, for precede logrotate, you should edit the nginx logrotate file, at /etc/logrotate.d/nginx
Add, under prerotate, this line:

su -l www-data -c "/bin/bash '__ FINALPATH__/misc/log-analytics/manage_import.sh' > '__ FINALPATH__/misc/log-analytics/lastlog_loganalytics_cron.log' 2>&1"

And replace __ FINALPATH__.

I reinstalled the Piwik. After that both the files were there with code.
The nginx file under /etc/logrotate.d/nginx did not had quote(") in the end.

It was
su -l www-data -c "/bin/bash '__ FINALPATH__/misc/log-analytics/manage_import.sh' > '__ FINALPATH__/misc/log-analytics/lastlog_loganalytics_cron.log' 2>&1 (no " in the end)

So I added the quote in the end of it.

Now it looks like this.

prerotate
                su -l www-data -c "/bin/bash '/var/www/piwik/misc/log-analytics/manage_import.sh' > '/var/www/piwik/misc/log-analytics/lastlog_loganalytics_cron.log' 2>&1"
                if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
                        run-parts /etc/logrotate.d/httpd-prerotate; \
                fi \
        endscript

When I do system check under settings of Piwik, I get error under Database abilities.

Error:

Try #1: LOAD DATA INFILE :
SQLSTATE[28000]: Invalid authorization specification: 1045 Access denied
for user ‘piwik’@‘localhost’ (using password: YES)[28000],
Try #2:
LOAD DATA LOCAL INFILE : SQLSTATE[42000]: Syntax error or access
violation: 1148 The used command is not allowed with this MySQL
version[42000]

The " at the end of line in logrotate is a mistake. It’s corrected.
But, his impact only logrotate’s execution, not cron’s execution.

And the LOAD DATA INFILE error, is not a fatal error. Just a inactive feature. But, i will work on this feature.

In state, piwik should working.

I have checked everything guided by you, but still Piwik is not showing any statistics.

Presently I am using it with the help of JavaScript code.

Is there anything other then this which I can try to make it work?

Can you post here your log? “/var/www/piwik/misc/log-analytics/lastlog_loganalytics_cron.log”

And check the permissions of loganalytics’s dir with this command:
ls -al /var/www/piwik/misc/log-analytics/

And post here the result.

The output of the /var/www/piwik/misc/log-analytics/lastlog_loganalytics_cron.log is:

Domaine traité: datamol.in
2014-11-14 04:00:03,407: [DEBUG] Accepted hostnames: all
2014-11-14 04:00:03,407: [DEBUG] Piwik URL is: https://datamol.in/piwik/local_alias
2014-11-14 04:00:03,407: [DEBUG] Authentication token token_auth is: ffc93df6cb9b5c4fa282bc63c9c3cb85
2014-11-14 04:00:03,407: [DEBUG] Resolver: static
2014-11-14 04:00:04,092: [DEBUG] Error when connecting to Piwik: HTTP Error 403: Forbidden
2014-11-14 04:00:06,112: [DEBUG] Error when connecting to Piwik: HTTP Error 403: Forbidden
2014-11-14 04:00:08,131: [DEBUG] Error when connecting to Piwik: HTTP Error 403: Forbidden
Traceback (most recent call last):
  File "/var/www/piwik/misc/log-analytics/import_logs.py", line 1737, in <module>
    resolver = config.get_resolver()
  File "/var/www/piwik/misc/log-analytics/import_logs.py", line 650, in get_resolver
    return StaticResolver(self.options.site_id)
  File "/var/www/piwik/misc/log-analytics/import_logs.py", line 991, in __init__
    'SitesManager.getSiteFromId', idSite=self.site_id
  File "/var/www/piwik/misc/log-analytics/import_logs.py", line 974, in call_api
    return cls._call_wrapper(cls._call_api, None, None, method, **kwargs)
  File "/var/www/piwik/misc/log-analytics/import_logs.py", line 963, in _call_wrapper
    raise Piwik.Error(message)
__main__.Error: Forbidden

And output of ls -al /var/www/piwik/misc/log-analytics/ is:

total 172
drwxr-xr-x  2 www-data root      4096 Nov 13 17:40 .
drwxr-xr-x 11 www-data root      4096 Oct 26 14:10 ..
-rw-r--r--  1 www-data root     13476 Nov 13 22:17 README.md
-rw-r--r--  1 www-data www-data   146 Nov 14 04:00 datamol.in-access_last_entry
-rw-r--r--  1 www-data www-data   179 Nov 14 04:00 datamol.in-error_last_entry
-r-xr-xr--  1 www-data root      1705 Nov 13 17:32 extract_log.sh
-rwxr-xr-x  1 www-data root     65152 Nov 13 22:17 import_logs.py
-rw-r--r--  1 www-data www-data  2600 Nov 14 04:00 lastlog_loganalytics_cron.log
-rw-r--r--  1 www-data www-data 63834 Nov 14 04:00 log_rewrite.log
-r-xr-xr--  1 www-data root      2456 Nov 13 17:32 manage_import.sh

Ok, so a permission error.

Can you check your nginx log?
sudo cat /var/log/nginx/datamol.in-error.log | grep piwik

And post here the content of your nginx config file
cat /etc/nginx/conf.d/datamol.in.d/piwik.conf

Ok, the output of sudo cat /var/log/nginx/datamol.in-error.log | grep piwik is:

2014/11/16 16:52:01 [error] 23001#0: *51193 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.1.99, server: datamol.in, request: "POST /piwik/index.php?date=2014-11-15&module=Live&action=getLastVisitsStart&segment=&idSite=1&period=day HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm-piwik.sock:", host: "datamol.in", referrer: "https://datamol.in/piwik/index.php?module=CoreHome&action=index&idSite=1&period=day&date=yesterday"
2014/11/17 04:00:07 [error] 17243#0: *54381 access forbidden by rule, client: 122.176.160.252, server: datamol.in, request: "POST /piwik/local_alias/ HTTP/1.1", host: "datamol.in"
2014/11/17 04:00:09 [error] 17241#0: *54382 access forbidden by rule, client: 122.176.160.252, server: datamol.in, request: "POST /piwik/local_alias/ HTTP/1.1", host: "datamol.in"
2014/11/17 04:00:11 [error] 17241#0: *54383 access forbidden by rule, client: 122.176.160.252, server: datamol.in, request: "POST /piwik/local_alias/ HTTP/1.1", host: "datamol.in"
2014/11/17 04:00:12 [error] 17241#0: *54386 access forbidden by rule, client: 122.176.160.252, server: datamol.in, request: "POST /piwik/local_alias/ HTTP/1.1", host: "datamol.in"
2014/11/17 04:00:14 [error] 17241#0: *54387 access forbidden by rule, client: 122.176.160.252, server: datamol.in, request: "POST /piwik/local_alias/ HTTP/1.1", host: "datamol.in"
2014/11/17 04:00:16 [error] 17241#0: *54388 access forbidden by rule, client: 122.176.160.252, server: datamol.in, request: "POST /piwik/local_alias/ HTTP/1.1", host: "datamol.in"
    /usr/share/ssowat/access.lua:14: in function </usr/share/ssowat/access.lua:1>, client: 192.168.1.99, server: datamol.in, request: "GET /piwik/plugins/CoreHome/images/favicon.ico HTTP/1.1", host: "datamol.in", referrer: "https://datamol.in/piwik/"
2014/11/17 22:45:21 [error] 2972#0: *3582 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 192.168.1.99, server: datamol.in, request: "GET /piwik/index.php?module=CoreUpdater&action=oneClickUpdate HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm-piwik.sock", host: "datamol.in", referrer: "https://datamol.in/piwik/index.php?module=CoreUpdater&action=newVersionAvailable"
2014/11/18 03:43:36 [error] 2971#0: *5571 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 192.168.1.99, server: datamol.in, request: "GET /piwik/index.php?module=CoreUpdater&action= HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm-piwik.sock", host: "datamol.in", referrer: "https://datamol.in/webmail/?_task=mail&_refresh=1&_mbox=INBOX&_page=1"
2014/11/18 04:00:14 [error] 2972#0: *5992 access forbidden by rule, client: 122.176.160.252, server: datamol.in, request: "POST /piwik/local_alias/ HTTP/1.1", host: "datamol.in"
2014/11/18 04:00:16 [error] 2969#0: *5993 access forbidden by rule, client: 122.176.160.252, server: datamol.in, request: "POST /piwik/local_alias/ HTTP/1.1", host: "datamol.in"
2014/11/18 04:00:18 [error] 2969#0: *5994 access forbidden by rule, client: 122.176.160.252, server: datamol.in, request: "POST /piwik/local_alias/ HTTP/1.1", host: "datamol.in"
2014/11/18 04:00:18 [error] 2969#0: *5995 access forbidden by rule, client: 122.176.160.252, server: datamol.in, request: "POST /piwik/local_alias/ HTTP/1.1", host: "datamol.in"
2014/11/18 04:00:20 [error] 2969#0: *5996 access forbidden by rule, client: 122.176.160.252, server: datamol.in, request: "POST /piwik/local_alias/ HTTP/1.1", host: "datamol.in"
2014/11/18 04:00:22 [error] 2969#0: *5997 access forbidden by rule, client: 122.176.160.252, server: datamol.in, request: "POST /piwik/local_alias/ HTTP/1.1", host: "datamol.in"
    /usr/share/ssowat/access.lua:14: in function </usr/share/ssowat/access.lua:1>, client: 192.168.1.99, server: datamol.in, request: "GET /piwik/index.php?module=Proxy&action=getCss&cb=55a11becefd247924b99e6323c57ad77 HTTP/1.1", host: "datamol.in", referrer: "https://datamol.in/piwik/"

And the output of cat /etc/nginx/conf.d/datamol.in.d/piwik.conf is:

location /piwik {
    alias /var/www/piwik/ ;
    if ($scheme = http) {
        rewrite ^ https://$server_name$request_uri? permanent;
    }
    index index.php;
    try_files $uri $uri/ index.php;
    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        fastcgi_pass unix:/var/run/php5-fpm-piwik.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param   REMOTE_USER   $remote_user;
        fastcgi_param  PATH_INFO $fastcgi_path_info;
    }

    # Include SSOWAT user panel.
    include conf.d/yunohost_panel.conf.inc;
}

# Alias autorisé seulement en local, destiné à l'exécution des scripts locaux.
location /piwik/local_alias {
    alias /var/www/piwik/ ;

    allow 127.0.0.1;
    allow 192.168.1.0/24;
    deny all;

    index index.php;
    try_files $uri $uri/ index.php;
    location ~ [^/]\.php(/|$) {
        fastcgi_pass unix:/var/run/php5-fpm-piwik.sock;
        include fastcgi_params;
    }
}

I think this issue started after I updated the piwik.

Ok, the error comes from your ip address 122.176.160.252. This is not a local address, but the nginx config impose a local address for security.

allow 192.168.1.0/24;
deny all;```

So, you might comment these security lines in your nginx conf. Or find why your ip address isn't a local ip.

I did not get it. Exactly what should I do in nginx conf ?

@Maniack_Crudelis: Allowed IP addresses are too restrictive, you don’t include all possible IP adresses from a private network with this rule - see this page. By the way, you don’t allow IPv6 addresses either.

You should replace it by something like:
allow 127.0.0.1; allow 10.0.0.0/8; allow 172.16.0.0/12; allow 192.168.0.0/16; allow fc00::/7; deny all;