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:
-
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.
-
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;
}
}
- 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;
}
- 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.