Problem setting up cron job for archiving

After setting up Matomo and waiting without any tracking results appearing for my website, I came across this suggestion and tried to set up scheduled tracking updating from this page:

When following the instructions there, when I go to save the file in nano, I get the following error: '/etc/cron.d/matomo-archive: No such file or directory'

Okay, maybe I set this up using crontab -e, but just to test things, I ran the following on the command line:

/usr/bin/php /home/redacted_username/path_to/matomo core:archive --url= >> /home/redacted_username/matomo_archive.log

This runs with no errors, and matomo_archive.log is created, however it is empty. Also, I still see no results on the Matomo dashboard (from the web browser.)

/usr/bin/php /home/kevinall/ core:archive --url= >> /home/kevinall/matomo_archive.log

/home/redacted_username/path_to/matomo is the directory containing the Matomo API. The index.php page is at the root there.

Part of this is I don’t understand fully the command line format - what file is php actually running? /home/redacted_username/path_to/matomo is a directory. If I just run /usr/bin/php /home/kevinall/ on the command line, PHP tells me the file is not found. But if I run the whole string, I don’t get an error, albeit it doesn’t seem to be updating anything. (I have manually loaded pages from the website myself in order to get tracking results btw.)

Note that I am using shared webhosting, and owner:group for all my files are username_redacted:username_redacted, not www-data.

I’m just very confused about all of this.

Update: Guessing that matamo.php at the root of the Matomo API is the script that should run, I tried running that, but the output is:

X-Powered-By: PHP/8.0.30
Content-type: text/html; charset=UTF-8

This resource is part of Matomo. Keep full control of your data with the leading free and open source web analytics & conversion optimisation platform. This file is the endpoint for the Matomo tracking API. If you want to access the Matomo UI or use the Reporting API, please use index.php instead.

I get the same message when running piwik.php.

Hi @KevinJones

No, matomo.php is the HTTP tracking API.

For your issue:

  • Do you see any tracking in the visits log? (if no visit, no data!, then no archive)
  • Is there any error in the :gear: > Diagnostic > System Check?
  • As first approach, you can activate the archiving via browser: :gear: > System > General Settings and select:
    • Archive reports when viewed from the browser: No Yes Sorry I made a mistake in my initial post)
    • Archive reports at most every X seconds : 3600 seconds

I looked at Diagnostic > System check. One of the flags says to set up a cron job, linking to the same page I posted here. Here’s the rub: nano /etc/cron.d/matomo-archive : When I go to write the file I get error because /etc/cron.d doesn’t exist. I cannot create it due to permissions because I am on shared hosting.

I set up a job using crontab -e, but I am not sure if it is accomplishing what I want or not. And as I said, I am not understanding the command clearly.

The php command shown in the linked page does not appear to pointing to a php script. From the linked page:

MAILTO="" 5 * * * * www-data /usr/bin/php /path/to/matomo/console core:archive --url= > /home/example/matomo-archive.log

I wish I understood the command string better.

So the system check is recommending that I set up a cron job. Yet there is a built in feature to “Archive reports at most every X seconds”. Is there something different that the cron job would do that the built-in archiving doesn’t?

Hi @KevinJones
Sorry, I made a mistake in my previous message. For the browser archiving, you have to set Yes for Archive reports when viewed from the browser setting.
Also you did not answer my question about the visits log (very important, as if you don’t track anything, you won’t get any data in any report).

Most of the command parameters are explained in the page you linked. Which param don’t you understand?

The CRON job is for Matomo instance with lots of tracking data. Also it allows to pre-process reports, before the analytics user want to see them. Matomo documentation describes also how to do if the CRON is not accessible form the server:

But the first thing is to test the basic data archiving launched by browser, as described in my 1st message.