Crontab to Automatically Archive the Reports Error

I tried to setup Crontab to Automatically Archive the Reports in Linux using the instruction on this page - How to Set up Auto-Archiving of Your Reports - Analytics Platform - Matomo

/etc/cron.d# nano piwik-archive

ADDED

MAILTO="bill@website-wi.com"
5 * * * * www-data /usr/bin/php7.0 /path/to/piwik/console core:archive --url=https://website-wi.com/piwik/ > /httpdocs/piwik/LOGS/piwik-archive.log

but when I tested it like the instructions said

su www-data -s /bin/bash -c "/usr/bin/php7.0 /path/to/piwik/console core:archive --url=https://website-wi.com/piwik/

I got this error.

Could not open input file: /path/to/piwik/console

I guess that’s because you don’t have a directory called /path/to/piwik/ on your server :smile:.

You need to change the path to the real directory where your Matomo installation lies.

Hi Lukas,

I think I added the correct path:

Code in piwik-archive file

MAILTO="bill@website-wi.com"
5 * * * * www-data /usr/bin/php7.0 /var/www/vhosts/website-wi.com/httpdocs/piwik/console core:archive --url=https://website-wi.com/piwik/ > /httpdocs/piwik/LOGS/piwik-archive.log

and tested with

su www-data -s /bin/bash -c "/usr/bin/php7.0 /var/www/vhosts/website-wi.com/httpdocs/piwik/console core:archive --url=https://website-wi.com/piwik/"

But Received this Error

[InvalidArgumentException]
The directory “/var/www/vhosts/website-wi.com/httpdocs/piwik/tmp/cache/tracker/” is not writable.

The “Tracker” Folder Permissions are 0755 or rwx r-x r-x

Not sure what they are suppose to be or if something else is wrong.

Hi,

0755 or rwx r-x r-x means that the owner of the file can write, while all other can only read. So your user (www-data) doesn’t seem to own the folder and therefore can’t write.

The easiest solution would be changing the owner:

sudo chown -R www-data:www-data /var/www/vhosts/website-wi.com/httpdocs/piwik/

Hi Lukas,

I ran - sudo chown -R www-data:www-data /var/www/vhosts/website-wi.com/httpdocs/piwik/

Which worked - Tested it with su www-data -s /bin/bash -c “/usr/bin/php7.0 /var/www/vhosts/website-wi.com/httpdocs/piwik/console core:archive --url=https://website-wi.com/piwik/”

BUT received this error when I went to PIWIK - The directory “/var/www/vhosts/website-wi.com/httpdocs/piwik/tmp/cache/tracker/” is not writable.

The hosting company and I did figure out why this was caused. I’m using Plesk with Linux and I have a different username in Plesk. Can I switch “www-data” to my plesk username or will that not work? If it will work would it look like - sudo chown -R myusername:myusername /var/www/vhosts/website-wi.com/httpdocs/piwik/ ?

Hi,

Yes you need to change the owner to the username of your webserver.

sudo chown -R myusername:myusername /var/www/vhosts/website-wi.com/httpdocs/piwik/

I put in - sudo chown -R myusername:myusername /var/www/vhosts/website-wi.com/httpdocs/piwik/ (using my real username) and got:

chown: invalid group:

That means your server dont have a group by that name. Try myusername:www-data.

1 Like

Hi Fabian,

Should I use myusername:www-data or myusername:mygroup?

Often mygroup is equal to myusername. But hat not worked, so the working solution would be myusername:www-data