Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Pixelairport's avatar

Matamo on forge (Ngnix settings)

I try to setup Matamo with forge, but when I try to install it with the Browser I get some warnings, that

  1. PHP FPM ignores .htaccess-rules
  2. I should configure the server, that access to some directories will be blocked.

Matomo say I should visit https://github.com/matomo-org/matomo-nginx#readme, but I really dont know what to do. Is there maybe a ngnix templat I can use? I already visited https://forgerecipes.com/, but could not find something.

I think the two problems can be solved with one solution... but I dont know how to go on. Hope somebody can help. Thx.

0 likes
4 replies
LaryAI's avatar
Level 58

The solution to this problem is to configure the Nginx server to allow access to the necessary directories and to ensure that PHP FPM is not ignoring .htaccess rules.

To do this, you can follow the instructions provided by Matomo on their GitHub page for Nginx configuration: https://github.com/matomo-org/matomo-nginx#readme.

Here are the basic steps:

  1. Create a new Nginx server block for your Matomo installation. You can use the default server block as a template and modify it as needed.

  2. Add the necessary location blocks to allow access to the Matomo directories. For example:

location /matomo {
    # Allow access to the Matomo directory
    allow all;
    # Disable PHP execution in this directory
    location ~ \.php$ {
        deny all;
    }
}

location /matomo/config {
    # Allow access to the Matomo config directory
    allow all;
    # Disable PHP execution in this directory
    location ~ \.php$ {
        deny all;
    }
}
  1. Add the necessary PHP-FPM settings to ensure that .htaccess rules are not ignored. For example:
location ~ \.php$ {
    # Pass PHP requests to PHP-FPM
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    # Set the document root for PHP requests
    fastcgi_param DOCUMENT_ROOT $realpath_root;
    # Set the SCRIPT_FILENAME parameter to the full path of the PHP file
    fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    # Include the standard fastcgi_params file
    include fastcgi_params;
    # Allow .htaccess files to be processed
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
}
  1. Save the Nginx configuration file and reload Nginx to apply the changes.

Once you have completed these steps, you should be able to install and use Matomo without any issues.

Pixelairport's avatar

Ok. I added this but it still not works... Is there someone who can help?

# SOF: Matomo
    location /home/forge-analytics/public {
        # Allow access to the Matomo directory
        allow all;
        # Disable PHP execution in this directory
        location ~ \.php$ {
            deny all;
        }
    }
    
    location /home/forge-analytics/public/config {
        # Allow access to the Matomo config directory
        allow all;
        # Disable PHP execution in this directory
        location ~ \.php$ {
            deny all;
        }
    }
    
    location ~ \.php$ {
        # Pass PHP requests to PHP-FPM
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        # Set the document root for PHP requests
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        # Set the SCRIPT_FILENAME parameter to the full path of the PHP file
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        # Include the standard fastcgi_params file
        include fastcgi_params;
        # Allow .htaccess files to be processed
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
    }
    # EOF: Matomo
mberneis's avatar

Norman,

I am planning to use Matamo with Forge as well. - Were you be able to get it working and if so would you share how you did it?

Thanks, Michael

Please or to participate in this conversation.