• Resolved ooksanen

    (@ooksanen)


    I have a site that refuses to archive reports automatically or manually and I noticed on diagnostics page and error logs that Matomo seems to have trouble connecting to database because of what seems to be missing database credentials. The credentials are saved in enviroment variables and not in wp-config.php and this seems to throw Matomo off. Any workarounds for this?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support dizzyatinnocraft

    (@dizzyatinnocraft)

    Sounds like your server’s PHP CLI doesn’t have access to those environment variables. How and where exactly are the environment variables defined?

    If you’d like a quick fix, you can try enabling the “Enable archiving via HTTP requests” setting in Matomo Analytics > Settings > Advanced. Otherwise, you’ll have to figure out how to make those environment variables available to your server’s PHP CLI.

    Thread Starter ooksanen

    (@ooksanen)

    Thanks for the suggestion @dizzyatinnocraft. Unfortunately that didn’t seem to solve the problem at least for manual archiving which seems to return the Matomo Analytics > Diagnostics > Troubleshooting page source in json response.

    The variables are defined in .env in project root and loaded with PHP dotenv.

    I’ll wait and see if the automatic archiving works. I’m also waiting for reponse from the host if they have any suggestions how to get the env-variables available for PHP CLI.

    Plugin Support dizzyatinnocraft

    (@dizzyatinnocraft)

    Unfortunately that didn’t seem to solve the problem at least for manual archiving which seems to return the Matomo Analytics > Diagnostics > Troubleshooting page source in json response.

    This is a separate issue that only happens on some hosting providers. Archiving may have succeeded. You’d want to check if new errors are in the system report logs or if data shows up in reports.

    The variables are defined in .env in project root and loaded with PHP dotenv.

    As far as I know, WordPress does not ever read environment variables for database credentials, but you (or code running on your behalf) can set the database credential consts to the result of getenv('...'), for example. I would expect this to be done in wp-config.php, but I suppose it could be done somewhere else. Do you know how your system sets the WordPress database credential consts?

    Thread Starter ooksanen

    (@ooksanen)

    Yep, seems like archiving works now with “archiving via HTTP requests” enabled and no new errors are shown in reports.

    Sorry if I was unclear. The credentials are indeed loaded from enviroment variables and set to WP constants in wp-config.php like this:

    define('DB_NAME', getenv('DB_NAME'));
    define('DB_USER', getenv('DB_USER'));
    define('DB_PASSWORD', getenv('DB_PASSWORD'));

    but for some reason Matomo gets empty values. If I define them as strings (not from enviroment variables) like

    define('DB_NAME', 'dbuser');

    etc. they seem to work properly.

    Plugin Support dizzyatinnocraft

    (@dizzyatinnocraft)

    @ooksanen how is your WP cron configured? For example, as a cron job that executes wp-cli or php directly? If that works then the environment variables might be present for PHP CLI. The only other possibility I can think of is that shell_exec() isn’t forwarding environment variables from the parent process to child processes. Are these things you can check for?

    Plugin Support dizzyatinnocraft

    (@dizzyatinnocraft)

    Hi @ooksanen, is this still a problem for you or have you gotten past it?

    Thread Starter ooksanen

    (@ooksanen)

    Hi @dizzyatinnocraft,

    archiving via HTTP requests seems to have fixed the problem of reports not gertting generated. Haven’t heard from the party responsible for the server about the config and why the enviroment variables aren’t available for Matomo, but the main problem is now resolved so I’ll close this thread.

    Thanks for your assistance!

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.