搜索数据库仅在 php 开发环境中工作

Search DB only working in php dev environment

我在 Ubuntu 20.04 的 VirutalBox 机器上安装了 Mapbender。 PostgreSQL、PostGIS 和 Geoserver 都安装在 VM 上。我创建了一个地图应用程序并添加了一个搜索路由器功能(按照文档中的说明进行操作)。搜索在开发环境中就像一个魅力一样工作,但在产品中,它不是。在开发环境中,它给出一个结果并将鼠标悬停在结果上突出显示该特征并单击结果移动并缩放地图到该特征。

在 prod 环境中,输入搜索字符串并按搜索时似乎没有任何反应。 devtools 报告内部服务器错误 500,这不是很有帮助。尽管在 Firefox 中,devtools 以红色显示 Referrer 策略“strict-origin-when-cross-origin”。

我已经将 Postgres 配置文件修改为 Listeners = * 和 host 0.0.0.0 以确保它不是数据库访问问题。

主机:Windows10 Pro 20H2

来宾计算机:Ubuntu 20.04

Mapbender 3.2.6

数据库 Postgresql 12.8 与 Postgis 3.0

WMS 通过 Geoserver 提供服务

PHP7.2

虽然我不确定我是否提供了所有信息来正确诊断问题,但如能说明如何调查和解决此问题,我们将不胜感激。

更新:

我修改了 php.ini 以通过设置以下开关启用错误日志记录:

error_reporting = E_ALL
display_errors = Off
log_errors = On
ignore_repeated_errors = On
ignore_repeated_source = Off
error_log = /var/log/apache2/php_errors.log

但是到目前为止没有错误被记录并且 php_errors.log 文件没有被创建。即使创建文件也不会对日志记录产生任何影响。我不确定我错过了什么。我想重申一下,搜索是在开发环境中进行的,所以看不出它是如何成为身份验证问题的。我正在 VM 内的浏览器上的产品环境中尝试搜索,因此使用 localhost 访问应用程序。

在开发工具上,我得到以下信息:

jquery.min.js:formatted:4210 POST` 
http://localhost/mapbender1/application/bh_admin/element/337/0-ed10fcc5-57e7-1f83-8a76-c32030225b85/search 500 (Internal Server Error)
send    @   jquery.min.js:formatted:4210
ajax    @   jquery.min.js:formatted:3992
n.<computed>    @   jquery.min.js:formatted:4044
getJSON @   jquery.min.js:formatted:4033
_search @   js:14187
(anonymous) @   jquery-ui.min.js:6
(anonymous) @   js:13976
dispatch    @   jquery.min.js:formatted:2119
r.handle    @   jquery.min.js:formatted:1998

单击 jquery.min.js:4210 时,以下行在文件中突出显示:

g.send(b.hasContent && b.data || null),

更新 2

根据@IonBazan 的建议,我找到了 prod.log 文件,尽管在不同的文件夹中,错误提示找不到数据库服务。日志文件位于:

var/www/mapbender1/app/logs

这是日志文件中的消息:

request.CRITICAL: Uncaught PHP Exception Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: "You have requested a non-existent service "doctrine.dbal.mobh_data_connection". Did you mean this: "doctrine.dbal.default_connection"?" at /var/www/mapbender1/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php line 348 {"exception":"[object] (Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException(code: 0): You have requested a non-existent service "doctrine.dbal.mobh_data_connection". Did you mean this: "doctrine.dbal.default_connection"? at /var/www/mapbender1/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:348)"} []

正如我之前提到的,开发应用程序能够访问该服务。我想这意味着 parameters.yml 和 config.yml 文件中的数据库连接参数是正确的。所以我觉得可能有一些缓存项需要更新,尤其是 Mapbender documentation 提到这个:

The cache-mechanism of the development-environment behaves differently: Not all files are cached, thus code changes are directly visible. Therefore the usage of the app_dev.php is always slower than the production-environment.

The directory app/cache contains the cache-files. It contains directories for each environment (prod and dev). But the mechanism of the dev-cache, as described before, behaves differently.

If changes of the Mapbender interface or the code are made, the cache-directory (app/cache) has to be cleared to see the changes in the application.

原来是文件夹权限问题。 dev 环境运行的原因是因为 dev 缓存的组件比 prod 少,这使得对 parameters.yml 和 config.yml 等配置文件的更改反映在 dev 而不是 prod 中。在设置和配置过程中的某个时候,cache/prod 文件夹的所有权转到了根目录,这使得 www-data 用户没有对该文件夹的适当访问权限。所以最重要的是,prod 缓存没有被更新,这使得数据库连接服务对 prod 环境不可见,尽管 parameters.yml 和 config.yml 具有正确的设置。

所以我做了以下操作,注意到我执行的某些步骤可能是不必要的,但在这个阶段我不会去寻找哪些步骤是不需要的。

第一步,停止 运行 服务(Apache 和 PHP 服务器):

sudo app/console server:stop
sudo service apache2 stop

清除产品缓存:

sudo app/console cache:clear --env=prod --no-debug

我还使用了带有无预热开关的 cache:clear 命令,这实际上让您留下了一个几乎空的缓存文件夹。我发出了这个命令,因为前一个命令在文件夹中留下了一些文件。

sudo app/console cache:clear --env=prod --no-warmup

安装资产:

sudo app/console assets:install web --env=prod

为 www-data 用户授予适当的文件夹权限:

sudo chown -R www-data:www-data /var/www/mapbender/app/cache
sudo chmod -R ug+w /var/www/mapbender/app/cache

启动 Apache 和 PHP 服务器:

sudo service apache2 start
sudo app/console server:start

注意app/console需要从文件夹/var/www/mapbender

执行

就像我之前提到的,可能有不必要的步骤,但这或多或少是我所做的,现在应用程序按预期运行。

免责声明:我不是开发人员,此处提供的信息来自多个来源,包括 Mapbender documentation