如何在 Laravel/OctoberCMS 网站的单独项目的子目录中 setup/access 页面?

How to setup/access page in subdirectory of separate project for a Laravel/OctoberCMS website?

我有一个网站 运行 我建立的 OctoberCMS 主题。它位于 DigitalOcean 的服务器上 运行。我需要在同一台服务器上添加一个单独的项目(即来自 Matomo 分析的代码)并访问 public 页面(例如 my_site.com/matomo)。我对 Laravel 和服务器配置还很陌生,所以我不确定我需要如何配置 index.php 文件或类似 .htaccess 的文件,以便我可以访问 my_site。com/matomo.

这是我的文件结构

/var/www/html/
     index.php (serves the pages of my project)
     artisan
     bootstrap/
     config/
     modules/
     plugins/
     server.php
     storage/
     themes/
     vendor/
     matomo/ (for installing the analytics for the site)
         index.php 
         matomo.php
         piwik.php
         config/
         a number of other files I can enumerate if necessary

我关注了 matomo 的 the instructions,但无济于事。当我尝试访问 my_site.com/matomo 时,我刚从我的网站上收到一个 404,其中包含我的主题格式。

我知道这应该不难。谢谢!

编辑:根据需要,我网站的主页位于 my_site.com。各个页面位于 my_site.com/page_name。这对我来说配置得很好。

现在,对于 Matomo,说明如下:

Open your FTP client and upload the Matomo files in ‘binary mode’ to the desired location on your web server. For example using the Filezilla FTP client, you can enable Binary mode transfer in the top menu Transfer > Transfer type > Binary). All files can be uploaded to a “analytics” sub-directory in your public www folder, for example http://yourdomain.org/analytics/ or you could setup Matomo in its own subdomain and upload all the files at http://analytics.example.org/ If you have SSH access to your server, you can use it instead of FTP as it is much faster: run wget https://builds.matomo.org/matomo.zip && unzip matomo.zip

因此,我使用 wget 选项将其添加到我认为是“public www 文件夹”的位置,/var/www/html。因此,这些说明让我相信我可以转到 my_site.com/analytics/,然后查看 GUI 网页以进行进一步的安装和设置。但是,这不起作用,因为它需要为我站点的其余部分设置的 404 页面。我也不知道我希望它能正常工作,因为 Matomo 中的 none 文件或文件夹被命名为“analytics”——我也试过 my_site.com/matomo作为记录。所以,这就是说,我不知道 Matomo 页面在哪里显示。

您不需要修复 index.php 中的任何内容。分析计数器可以添加到

之间的页面布局 (~/themes/mytheme/layout/mylayout.htm)
<head>
...
</head>

<body>
...
</body>

根据您的仪表指示

我对 Matomo 没有任何经验,但从问题中我了解到您要安装两个软件 X 作为 CMS 和 Y 作为 Matomo

您的网络服务器(我假设 Apache 是网络服务器)将向以下路径提供所有请求:/var/www/html/index.php。属于软件 X。您的请求 my_site.com/matomo 将提供给软件 X,并且由于 X 不期望此请求,它将输出 404 Not Found 错误。

第一个解决方案: 这是不好的解决方案,更难的解决方案是编辑 /var/www/html/index.php 并将其与 Y index.php 结合,如果请求中有 matomo URL.

方案二:最好的解决方案是将X和Y分开,可以有几种方式:

  • 您可以合并 /var/www/html/x 下一个文件夹中的所有 X 文件,以及 /var/www/html/y 下文件夹中的所有 Y 文件。然后您可以使用以下 URL my_site.com/x 访问 x 并使用 my_site.com/y.

    访问 y
  • 如果第一种方法不可行,因为您需要像 my_site.com 一样以 X 作为根 URL。然后你可以将所有的Y文件合并到下面的文件夹/var/www/html/matomo下。然后你需要创建子域(Y的虚拟主机)。

使用 Ubuntu 和 Apache 创建虚拟主机:

sudo touch /etc/apache2/sites-available/matomo.my_site.com.conf

然后使用您喜欢的文本编辑器编辑文件,我将使用 nano

sudo nano /etc/apache2/sites-available/matomo.my_site.com.conf

并通过以下代码:

<VirtualHost *:80>
    ServerAdmin admin@my_site.com
    ServerName matomo.my_site.com
    DocumentRoot /var/www/html/matomo/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

my_site.com 更改为您的域。

然后你需要启用虚拟主机

sudo a2ensite /etc/apache2/sites-available/matomo.my_site.com.conf

然后重启apache看看效果。

sudo systemctl restart apache2

您的 matomo 将在以下 URL matomo.my_site.com

如果您没有使用 Ubuntu 或 Apache,请告诉我您使用什么来更新我的答案。

参见https://github.com/octobercms/october/issues/1615。您需要将要允许访问的文件夹添加为 October CMS .htaccess 的排除项,然后还禁用禁用 运行 除 index.php 以外的任何 PHP 文件的行。

所以用

替换RewriteEngine On
RewriteEngine On

# Allow access to Matomo
RewriteRule ^(matomo)($|/) - [L]

然后把RewriteCond %{REQUEST_FILENAME} \.php$注释掉就变成了# RewriteCond %{REQUEST_FILENAME} \.php$.