Home > Software engineering >  Search DB only working in php dev environment
Search DB only working in php dev environment

Time:09-17

I have setup Mapbender on Ubuntu 20.04 on a VirutalBox machine. PostgreSQL, PostGIS and Geoserver are all installed on the VM. I created a map application and added a search router function (followed the instructions in the documentation). The search is working like a charm in the dev environment but in the prod, it is not. In the dev environment, it is giving a result and hovering the mouse over the result highlights the feature and clicking on the result moves and zooms the map to the feature.

In the prod environment, nothing seems to happen when typing the search string and pressing search. The devtools report an internal server error 500, which is not very helpful. Although, in Firefox, the devtools show Referrer policy "strict-origin-when-cross-origin" in red.

I have already modified the Postgres configuration files to Listeners = * and host 0.0.0.0 to make sure it is not a database access problem.

Host Machine: Windows 10 Pro 20H2

Guest Machine: Ubuntu 20.04

Mapbender 3.2.6

Database Postgresql 12.8 with Postgis 3.0

WMS Served through Geoserver

PHP7.2

While I am not sure I provided all the information to properly diagnose the problem, any indication on what to do to investigate this issue and solve it are appreciated.

Update:

I modified php.ini to enable error logging by setting the following switches:

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

But no errors are being logged so far and php_errors.log file is not being created. Even creating the file is not having any effect on the logging. Am not sure what I am missing. I want to reiterate though that the search is working in the dev environment so can't see how it can be an authentication issue. I am trying the search in the prod environment on a browser from within the VM, so using localhost to access the application.

On dev tools I get the following:

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

When clicking on jquery.min.js:4210, the following line is highlighted in the file:

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

Update 2

Following @IonBazan suggestion, I found the prod.log file, albeit in a different folder, and the error indicates that the database service cannot be found. The log file was in:

var/www/mapbender1/app/logs

And this is the message in the log file:

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)"} []

As I have mentioned before, the dev app is capable of accessing the service. This means, I suppose, that the DB connection parameters are correct in the parameters.yml and config.yml files. So I have a feeling there might be some cached item that needs updating, especially that Mapbender documentation mentions this:

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.

And

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.

CodePudding user response:

So this turned out to be a folder permission issue. The reason why the dev environment was working was because the dev caches less components than the prod, which makes changes made to configuration files like parameters.yml and config.yml reflected in the dev and not in the prod. At some point during the setup and configuration process, the ownership of the cache/prod folder went to root which left the www-data user without the proper access rights to the folder. So bottom line, the prod cache was not being updated which made the database connection service invisible to the prod environment, although the parameters.yml and config.yml had the correct settings.

So what I did was the following, noting that there are steps I performed which might have been unnecessary, but at this stage I will not be looking into finding out which step was not needed.

First step, stop the running services (Apache and PHP server):

sudo app/console server:stop
sudo service apache2 stop

Clear the prod cache:

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

I also used the cache:clear command with the no-warmup switch which essentially leaves you with an almost empty cache folder. I issued this command since the previous one left some files in the folder.

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

Install the assets:

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

Give www-data user the proper folder permissions:

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

Start Apache and PHP server:

sudo service apache2 start
sudo app/console server:start

Note that app/console needs to be executed from the folder /var/www/mapbender

Like I mentioned earlier, there might be unnecessary steps but this is more or less what I did and now the app is working as expected.

Disclaimer: I am not a developer and the information presented here was assembled from more than one source, including the Mapbender documentation.

  • Related