Set up Cron not working at all

Hi

I have Matomo self-hosted installed on a server that runs Rocky Linux 8.7 and these specs

Matomo version: 4.14.1
MySQL version: 10.3.35-MariaDB
PHP version: 8.1.17

and I am trying to fix this recommendation in Administration > Diagnostic > System Check:

Set up Cron (faster report-loading)
For optimal performance and a speedy Matomo, it is highly recommended to set up a crontab to automatically archive your reports, and to disable browser triggering in the Matomo settings. Learn more."

I followed the guide here , created the /etc/cron.d/matomo-archive file and tweaked these lines:

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

I added my own email and for the 2nd line I tried to find the correct paths, where domain.com is the domain I used to set it up on:

  • www-data is supposed to be an user but in my case the username created for this domain has the same name as the domain, so it was domain.com
  • /usr/bin/php i checked it using which php and got the same path
  • /path/to/matomo/console in my case I figured out it is /home/domain.com/public_html/analytics (I created a subfolder analytics where I installed Matomo instead of root)
  • http://example.org/matomo/ is my Matomo URL path: https://domain.com/analytics/
  • /home/example/matomo-archive.log is this path I figured /home/domain.com/public_html/analytics/matomo-archive.log

So my final 2 code lines that I updated inside file /etc/cron/d/matomo-archive became:

MAILTO="hello@domain.com"
5 * * * * domain.com /usr/bin/php /home/domain.com/public_html/analytics core:archive --url=https://domain.com/analytics/ > /home/domain.com/public_html/analytics/matomo-archive.log

In the instructions it says

/path/to/matomo/console is the path to your Matomo app on your server. For example it may be /var/www/matomo/console

I am not sure if my path is correct to be honest, as I couldn’t find anything in /var/www/matomo : (

So then I modified this command as per guide above:

su www-data -s /bin/bash -c "/usr/bin/php /path/to/matomo/console core:archive --url=http://example.org/matomo/"

to this command:

su domain.com -s /bin/bash -c "/usr/bin/php /home/domain.com/public_html/analytics core:archive --url=https://domain.com/analytics/"

and ran it in the terminal in order to test if the crontab is working; when I ran it in the terminal, nothing happened, it did not give any error or message or showed any domains.

I think I have made a mistake somewhere but I keep going back and can’t find the solution to this.

I’ve really tried different things to fix this but I still can’t get the crontab working. I even tried changing the username in the file to root and ran the same command with su root -s ... but no success either.

If anyone has any advice on this how to get the crontab working, would be soo grateful!

Thank you so much!

Yay!

Fixed it finally, I found the solution, it was starring in my face the whole time.

For other Matomo users that encountered similar issues, this is the workaround it:

As per instructions here you will create a file in /etc/cron.d/matomo-archive with 2 lines of code:

MAILTO="youremail@example.com"
5 * * * * /usr/bin/php /path/to/matomo/console core:archive --url=http://example.org/matomo/ > /dev/null
  • As you can see no need to add the user in the 2nd line of code

As I am setting up the crontab as a user, I’ve used the 2nd line instead of using root.

The trick is that there is actually a folder in your /path/to/matomo/console (duh!).

To test it, go to your terminal SSH and run:

su user_used -s /bin/bash -c "/usr/bin/php /path/to/matomo/console core:archive --url=http://example.org/matomo/"

The user_used would be usually the user you’ve setup for the webserver, so check it in Scheduled Cron Jobs if unsure, or check in your settings when you’ve created the server.

Once you run the command above, you will see it all green and nice in SSH, meaning it is working : )

Hope this helps other users.