Skip to content

Matomo MCP Authentication Fails With 401 Behind Apache #24572

@kylebarrow

Description

@kylebarrow

Environment

  • Matomo hosted at analytics.bunnyapartment.com
  • Apache: Apache/2.4.67 (Debian)
  • PHP: 8.4.21
  • PHP SAPI: Apache 2 Handler
  • Document root: /var/www/matomo

Issue

Matomo MCP requests were failing with 401 Unauthorized, even when the client was sending the expected Authorization header.

Cause

Apache was not exposing the incoming Authorization header to PHP as HTTP_AUTHORIZATION. As a result, Matomo/MCP could not read the bearer token or auth credentials and treated the request as unauthenticated.

Solution

Add the following line to Matomo’s .htaccess file:

SetEnvIf Authorization "^(.*)$" HTTP_AUTHORIZATION=$1

Result

After adding this rule, Apache forwards the Authorization header into the PHP environment as HTTP_AUTHORIZATION, allowing Matomo MCP authentication to succeed instead of returning 401.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions