Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matomo - Siteground Incompatibility: fails to find PHP cli binary #20609

Closed
esurov opened this issue Apr 20, 2023 · 1 comment
Closed

Matomo - Siteground Incompatibility: fails to find PHP cli binary #20609

esurov opened this issue Apr 20, 2023 · 1 comment
Labels
answered For when a question was asked and we referred to forum or answered it.

Comments

@esurov
Copy link

esurov commented Apr 20, 2023

Matomo - Siteground Incompatibility: fails to find PHP cli binary

Context

Matomo Analytics Wordpress Plugin turned out to have a problem running on SiteGround hosting.

Problem.

We have discovered that trying to use the plugin throws a couple of Critical Errors:

  • PHP cli Version: Your PHP cli version is not compatible with the Matomo requirements. Please upgrad e your PHP cli version, otherwise, you might have some archiving errors
  • MySQLi support: Your PHP cli does not load the MSQLi extension. You might have archiving problems in Matomo but also others problems in your WordPress cron tasks. You should enable this extension

Requirement.

The plugin itself requires PHP 7.2.5+ while we have PHP 7.4.33 so the PHP version was not the issue.

Requirements for Matomo On-Premise - Analytics Platform - Matomo

Research.

After doing some deep level code debug of the Matomo plugin I discovered that the module of plugin that is trying to find the PHP cli binary mistakenly finds a cgi-bin instead which does not support the cli params sent to it and Matomo can’t parse it’s output.

Expected Behavior

Current Behavior

Possible Solution

In order to fix this issue we need to swap two blocks of code in Matomo plugin wp-content/plugins/matomo/app/core/CliMulti/CliPhp.php line 43:

so it should read as follows:

        if (!$this->isValidPhpType($bin) && function_exists('shell_exec')) {
            $bin = @shell_exec('which php');
        }

        if (empty($bin)) {
            $possiblePhpPath = PHP_BINDIR . ('\\' === \DIRECTORY_SEPARATOR ? '\\php.exe' : '/php');
            $bin = $this->getPhpCommandIfValid($possiblePhpPath);
        }

The reason for this is that which php command shall run first as it returns the correct path to the php binary /usr/local/bin/php while the possiblePhpPath gives a mistaken path to cgi-bin file /usr/local/php74/bin/php

Installation.

After each fresh installation of the Matomo plugin we need to perform this monkey path by changing wp-content/plugins/matomo/app/core/CliMulti/CliPhp.php at line 43 from this:

        if (empty($bin)) {
            $possiblePhpPath = PHP_BINDIR . ('\\' === \DIRECTORY_SEPARATOR ? '\\php.exe' : '/php');
            $bin = $this->getPhpCommandIfValid($possiblePhpPath);
        }

        if (!$this->isValidPhpType($bin) && function_exists('shell_exec')) {
            $bin = @shell_exec('which php');
        }

to this:

        if (!$this->isValidPhpType($bin) && function_exists('shell_exec')) {
            $bin = @shell_exec('which php');
        }

        if (empty($bin)) {
            $possiblePhpPath = PHP_BINDIR . ('\\' === \DIRECTORY_SEPARATOR ? '\\php.exe' : '/php');
            $bin = $this->getPhpCommandIfValid($possiblePhpPath);
        }

Said that, I will try to reach out to the Matomo plugin support to report the bug and offer this solution as a fix.

Steps to Reproduce (for Bugs)

  1. Install and Activate Matomo WP plugin
  2. Open Matomo System report from the WP Admin [/wp-admin/admin.php?page=matomo-systemreport]

Your Environment

  • Matomo Version:
  • PHP Version: PHP 7.4.33
  • Server Operating System: Linux gfram1028.siteground.biz 3.12.18-clouder0 Updates ? #3 SMP PREEMPT Wed May 25 12:13:20 EEST 2022 x86_64 x86_64 x86_64 GNU/Linux
  • Additionally installed plugins: Elementor, ACF, All-in-One WP Migration
  • Browser: Chrome
  • Operating System: MacOS
@esurov esurov added Potential Bug Something that might be a bug, but needs validation and confirmation it can be reproduced. To Triage An issue awaiting triage by a Matomo core team member labels Apr 20, 2023
@bx80
Copy link
Contributor

bx80 commented Apr 20, 2023

Hi @esurov, thanks for reporting this.

Although changing the order of the CLI binary detection solves the issue with siteground hosting, on other providers it may be less reliable to prefer which php over PHP_BINDIR.

There is a config.ini.php setting which can be used to specify the PHP binary to use, this should allow you to force use of a particular binary without needing to change any code.

; The absolute path to a PHP binary file in case Matomo cannot detect your PHP binary. If async CLI archiving cannot be
; used on your server this may make it work. Ensure the configured PHP binary is of type CLI and not for example cgi or
; litespeed. To find out the type of interface for a PHP binary execute this command: php -r "echo php_sapi_name();"
php_binary_path = ""

Feel free to reopen this issue if there any problems using the config setting.

@bx80 bx80 closed this as not planned Won't fix, can't repro, duplicate, stale Apr 20, 2023
@bx80 bx80 added answered For when a question was asked and we referred to forum or answered it. and removed Potential Bug Something that might be a bug, but needs validation and confirmation it can be reproduced. To Triage An issue awaiting triage by a Matomo core team member labels Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered For when a question was asked and we referred to forum or answered it.
Projects
None yet
Development

No branches or pull requests

2 participants