Installation

1. Vorarbeiten

sudo apt update && sudo apt dist-upgrade -y
sudo apt install -y bzip2 certbot cockpit cockpit-podman composer gnupg mariadb-server nginx php php-fpm php-dom php-gd phpmyadmin podman python3-certbot-nginx php-pear php-dev clang libclang-dev pkg-config
sudo apt purge apache2 -y

sudo pecl install mongodb-1.21.0
sudo mkdir -p /var/www/maps && sudo chown www-data:www-data /var/www/maps && sudo chmod 0777 /var/www/maps
sudo mkdir -p /var/www/map_tests && sudo chown www-data:www-data /var/www/map_tests && sudo chmod 0777 /var/www/map_tests
sudo mkdir -p /var/www/PreviewMapsTiles && sudo chown www-data:www-data /var/www/PreviewMapsTiles && sudo chmod 0777 /var/www/PreviewMapsTiles
sudo mkdir -p /var/www/project_files && sudo chown www-data:www-data /var/www/project_files && sudo chmod 0777 /var/www/project_files

MySQL root Passwort setzen und Datenbank anlegen

sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED BY '<root_password>';
CREATE USER 'locrmap'@'localhost' IDENTIFIED BY '<password>';

CREATE DATABASE maps;
GRANT ALL ON maps.* TO 'locrmap'@'localhost';

CREATE DATABASE geonames;
GRANT ALL ON geonames.* TO 'locrmap'@'localhost';

CREATE DATABASE maps_url_queues;
GRANT ALL ON maps_url_queues.* TO 'locrmap'@'localhost';

CREATE DATABASE polyline_dbs;
GRANT ALL ON polyline_dbs.* TO 'locrmap'@'localhost';

Datenbank von "alten" MapsServer exportieren

mysqldump -u root -p maps > maps.sql

Datenbanken auf neuen Server kopieren und entpacken

scp maps.sql serverconnect@maps<x>.locr.com:~/

scp u443812-sub2@u443812.your-storagebox.de:/geonames.sql.tar.bz2 ~
tar xf geonames.sql.tar.bz2

scp u443812-sub2@u443812.your-storagebox.de:/maps_url_queues.sql.tar.bz2 ~
tar xf maps_url_queues.sql.tar.bz2

scp u443812-sub2@u443812.your-storagebox.de:/polyline_dbs.sql.tar.bz2 ~
tar xf polyline_dbs.sql.tar.bz2

Datenbanken auf neuem Server importieren

mysql -u root -p maps < maps.sql
mysql -u root -p geonames < geonames.sql
mysql -u root -p maps_url_queues < maps_url_queues.sql
mysql -u root -p polyline_dbs < polyline_dbs.sql

2. Installation aus den Quellen

mkdir -p ~/projects && cd ~/projects
git clone --recurse-submodules git@bitbucket.org:locr/phpmapcreate.git PhpMapCreate

cd PhpMapCreate && composer install --no-dev
cd src/libraries/locr-php && composer install --no-dev

cd ../../../ && sudo mkdir -p /etc/locr && sudo cp installation_files/maps-server.ini /etc/locr

cd /var/www && sudo ln -s ~/projects/PhpMapCreate/src PhpMapCreate
sudo chmod +rx /home/serverconnect

3. /etc/containers/registries.conf anpassen

# Zeile einblenden und docker.io eintragen
unqualified-search-registries = ["docker.io"]

4. Container Service installieren

cd ~/projects/PhpMapCreate/
./scripts/install_service.sh

5. Update script im home-Verzeichnis erstellen

cat <<EOF >~/update_maps_server.sh
#!/usr/bin/env bash

cd ${PWD} && git pull && git submodule update --init --recursive

cd scripts && ./update_service.sh
EOF

chmod +x ~/update_maps_server.sh

6. nginx konfigurieren

# default Konfiguration entfernen
sudo rm /etc/nginx/sites-enabled/default

# für den Zugriff unter einer subdomain => https://maps1.<domain.tld>/
sudo cp installation_files/nginx/sites-available/maps1.locr.com /etc/nginx/sites-available
sudo ln -s /etc/nginx/sites-available/maps1.locr.com /etc/nginx/sites-enabled/maps1.locr.com

6.1. /etc/nginx/nginx.conf anopassen

http {
    ...

    ##
    # PHP Handler
    ##
    upstream php {
        server unix:/run/php/php8.3-fpm.sock;
    }

    ##
    # WebSocket Handling
    ##
    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }

    ##
    # For the statistics under `/administration/` in the top bar (ServerLoad, CPU-Temperature, HDD, maps.accesses).
    ##
    upstream wsbackend {
        server 127.0.0.1:8088;
    }

    ...
}

6.2. /etc/nginx/conf.d/php anlegen

location ~ \.php$ {
    fastcgi_pass php;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_read_timeout 86400;

    include fastcgi_params;
}

6.3. /etc/nginx/conf.d/php_for_maps_server anlegen

location ~ \.php$ {
    include fastcgi_params;

    fastcgi_pass 127.0.0.1:18080;

    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_read_timeout 3600;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
}

6.4. /etc/nginx/conf.d/default_denies anlegen

location ~ /(\.git|\.ht|node_modules) {
    deny all;
}

6.5. /etc/nginx/conf.d/phpmyadmin anlegen

location ~ ^/phpmyadmin {
    root /usr/share;

    include conf.d/php;
}

6.6. /etc/nginx/conf.d/lmds anlegen

location ~ ^/(files|status|tasks|queue|lock_request|release_request|configuration|count_all_tasks|list_long_running_tasks|locrmap|ddserver|kill_task|stop_lmds|reorder_server|server|synchronization)/ {
    proxy_pass http://127.0.0.1:2048;
    proxy_set_header Host $host;
    proxy_read_timeout 28800s; # x3 = 86400s
}

6.7. /etc/nginx/conf.d/maps_server_locations anlegen

location /archives {
#   alias /var/www/files;
    root /var/www;
    autoindex on;
}

location /tiles {
    alias /var/www/PreviewMapsTiles;
}

location ~* /(maps|map_tests|icon_temp) {
    root /var/www;
}

6.8. /etc/nginx/conf.d/maps_server_rewrites anlegen

if ($request_method = GET) {
    rewrite "^/api/vms2/assets/(.+)$" /api/vms2.php?action=get_asset&path=$1 last;
    rewrite "^/api/vms2/fonts/(.+)$" /api/vms2.php?action=get_font&name=$1 last;
    rewrite "^/api/vms2/style/([^\/]+)$" /api/vms2.php?action=get_style&name=$1 last;
    rewrite "^/api/vms2/tile/([0-9]+)/([0-9]+)/([0-9]+)\.(dat)$" /api/vms2.php?action=get_tile&x=$3&y=$2&z=$1&format=$4 last;
}

6.9. /etc/nginx/conf.d/maps_server_websockets anlegen

location /ws/ {
    proxy_pass http://wsbackend;
    proxy_http_version 1.1;

    proxy_set_header Host localhost;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
}

nginx Konfiguration testen und neustarten

sudo nginx -t
sudo systemctl restart nginx

7. Let’s Encrypt Zertifikat installieren

sudo certbot --nginx -d maps1.locr.com

8. mariadb konfigurieren

Datei /etc/mysql/mariadb.conf.d/50-server.cnf anpassen

[mysqld]
max_connections = 1000

MariaDB neustarten

sudo systemctl restart mariadb

9. Verbindung für Icon-Server einrichten (/etc/locr/icon-client.ini)

[SERVER]
auth_username = serverconnect
auth_password = <myPassword>

10. Verbindung für POI-Server einrichten (/etc/locr/poi-client.ini)

[SERVER]
auth_username = serverconnect
auth_password = <myPassword>

11. Kachelabrufe des VMS2 authorisieren (/etc/locr/maps-server.ini)

Der Schlüssel wird im User-Server dem Benutzer MapsServer zugeordnet und bei dem Abruf von VMS2-Karten benötigt.

VMS2_IMAGE_SERVER_ACCESS_KEY = <maps_server_access_key>

12. Batch-Processing (Batch-Tool) einrichten

12.1. MongoDB installieren

curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \
   sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg \
   --dearmor

echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list

sudo apt update

sudo apt install -y mongodb-org

sudo systemctl start mongod

12.2. GUI für MongoDB: Compass

12.3. aktuelle Datenbank exportieren

mongodump --archive > \*.bson
tar -cjf mongodb.tar.bz2 \*.bson

12.4. Um eine spezifische Datenbank zu löschen

mongosh
use <db-name>;
db.dropDatabase();

12.5. Um mehrere alte MongoDB Datenbanken zu löschen

mongosh
db.adminCommand({ listDatabases: 1 }).databases
  .map(db => db.name)
  .filter(name => /^mein_schema_/.test(name)) // Regex für die zu löschenden Datenbanken anpassen
  .forEach(name => {
    print("Lösche "+name);
    db.getSiblingDB(name).dropDatabase();
  });

12.6. MongoDB aus Backup (Hetzner StorageBox) wiederherstellen

scp u443812-sub2@u443812.your-storagebox.de:/mongodb-\(<day>\).tar.bz2.enc .
openssl aes-256-cbc -d -pbkdf2 -in mongodb-\(<day>\).tar.bz2.enc -out mongodb-\(<day>\).tar.bz2 -k <password>
tar xjf mongodb-\(<day>\).tar.bz2
mongorestore --archive --drop --preserveUUID < \*.bson

12.7. cron-Jobs einrichten

crontab -e

Einträge für die Cron-Jobs hinzufügen (Achtung: hier als Beispiel für maps5.locr.com).

0 0 * * 1 /usr/bin/curl --cookie "MapCreateUsername=locr;MapCreatePassword=b21a98fdda3cd7d6caefd506b390fad3" https://maps5.locr.com/functions/ajax/request_tester.php?send_results
0 0 * * * /usr/bin/curl --cookie "MapCreateUsername=locr;MapCreatePassword=b21a98fdda3cd7d6caefd506b390fad3" https://maps5.locr.com/cronjobs/test_map_builder.php
0 4 1 * * cd /var/www/PhpMapCreate/cronjobs && ./backup_maps_database.php >> /home/serverconnect/backup_maps_database.log
0 1 * * * /usr/local/bin/rusty-backup --backup-settings-file=/home/serverconnect/backup-settings.xml
# * * * * * /usr/bin/curl --cookie "MapCreateUsername=locr;MapCreatePassword=b21a98fdda3cd7d6caefd506b390fad3" https://maps5.locr.com/api/url_queue.php?action=start_next > /dev/null 2>&1
0 * * * * /usr/bin/curl https://maps5.locr.com/cronjobs/check_mongodb_status.php >> /home/serverconnect/check_mongodb_status.log 2>&1
0 6 * * * cd /var/www/PhpMapCreate/cronjobs && ./check_user_packages.php >> /home/serverconnect/check_user_packages.log
0 2 * * * cd /var/www/PhpMapCreate/cronjobs && ./send_dayly_user_access_reports.php --host=maps5.locr.com > /dev/null 2>&1
5 * * * * cd /var/www/PhpMapCreate/cronjobs && ./check_batch_tool_processes.php > /dev/null 2>&1
0 3 * * * cd /var/www/PhpMapCreate/cronjobs && ./send_dayly_batch_report.php > /dev/null 2>&1
sudo crontab -u www-data -e
0 3 * * * cd /var/www/PhpMapCreate/cronjobs && ./remove_old_batch_projects.php
sudo crontab -e
#0 5 1 */2 * cd /home/serverconnect && ./update_lets_encrypt_certificate.sh
0 2 15 * * test -e /var/lock/delete-old-maps && exit 0 || (touch /var/lock/delete-old-maps;find /var/www/maps -type f -ctime +30 -delete;rm /var/lock/delete-old-maps) > /dev/null 2>&1
[maps_server]
# BATCH_PROCESSING_URL = https://maps<x>.locr.com/batch-processing/
BATCH_PROCESSING_URL = https://batch.locr.com/