Benutzer-Werkzeuge

Webseiten-Werkzeuge


software:middleware:installation

Dies ist eine alte Version des Dokuments!


Installation der Middleware

This installs the middleware and the frontend. You also need to install the logger (vzlogger).

Voraussetzungen

  • PHP 7.1 (nicht verfügbar in Raspbian Stretch!)
  • Doctrine 2.5
  • MySQL, MariaDB, PostgreSQL oder SQLite + PDO Treiber
  • APC (optional, aber empfohlen)
  • Apache mod_rewrite (optional)

Es eigenen sich hier Debian oder Ubuntu, sowie für den Raspberry Pi: Raspbian oder Raspbian Light.(„Buster“-Version, oder „Stretch“ mit PHP Update)
Die Abhängigkeiten lassen sich schnell mit folgendem Befehl installieren:

sudo apt-get install git-core php7.1-cli php7.1-mysql php-apcu mysql-server mysql-client php7.1-xml php-mbstring ca-certificates 

bzw. für PostgreSQL

apt-get install git-core php7.1-cli php7.1-pgsql php-apcu postgresql-8.4

Für die manuelle Installation wird zudem „curl“ benötigt.

Vollautomatisiert mit Ansible und DebOps

Install-Skript (empfohlene Installationsmethode)

wget https://raw.github.com/volkszaehler/volkszaehler.org/master/bin/install.sh
bash install.sh

Das sollte dann ablaufen:

pi@raspberrypi:~ $ bash install.sh
volkszaehler.org installation script

checking prerequisites: php: /usr/bin/php
 mysql: /usr/bin/mysql
 awk: /usr/bin/awk
 sed: /bin/sed
 grep: /bin/grep
 wget: /usr/bin/wget
 mktemp: /bin/mktemp
 mkdir: /bin/mkdir
 git: /usr/bin/git

checking php version: 7.3.3-1 >= 7.1, ok

volkszaehler setup...
volkszaehler path? [/home/pi/volkszaehler.org]
git clone volkszaehler.org into /home/pi/volkszaehler.org
Cloning into '/home/pi/volkszaehler.org'...
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 11981 (delta 0), reused 0 (delta 0), pack-reused 11977
Receiving objects: 100% (11981/11981), 7.51 MiB | 752.00 KiB/s, done.
Resolving deltas: 100% (6760/6760), done.
link from webserver to volkszaehler directory? [/var/www/volkszaehler.org]
linking /var/www/volkszaehler.org to /home/pi/volkszaehler.org

checking composer...
composer: /usr/local/bin/composer

installing dependencies...
~/volkszaehler.org ~
Loading composer repositories with package information
Updating dependencies
Package operations: 52 installs, 0 updates, 0 removals
  - Installing symfony/routing (v4.2.4): Downloading (100%)
  - Installing symfony/polyfill-mbstring (v1.11.0): Downloading (100%)
  - Installing symfony/http-foundation (v4.2.4): Downloading (100%)
  - Installing ralouphie/getallheaders (2.0.5): Downloading (100%)
  - Installing psr/http-message (1.0.1): Downloading (100%)
  - Installing guzzlehttp/psr7 (1.5.2): Downloading (100%)
  - Installing react/promise (v2.7.1): Downloading (100%)
  - Installing react/event-loop (v1.1.0): Downloading (100%)
  - Installing react/promise-timer (v1.5.0): Downloading (100%)
  - Installing evenement/evenement (v3.0.1): Downloading (100%)
  - Installing react/stream (v1.1.0): Downloading (100%)
  - Installing react/cache (v0.5.0): Downloading (100%)
  - Installing react/dns (v0.4.16): Downloading (100%)
  - Installing react/socket (v1.2.0): Downloading (100%)
  - Installing ratchet/rfc6455 (0.2.4): Downloading (100%)
  - Installing cboden/ratchet (v0.4.1): Downloading (100%)
  - Installing symfony/contracts (v1.0.2): Downloading (100%)
  - Installing symfony/console (v4.2.4): Downloading (100%)
  - Installing doctrine/instantiator (1.2.0): Downloading (100%)
  - Installing doctrine/event-manager (v1.0.0): Downloading (100%)
  - Installing doctrine/cache (v1.8.0): Downloading (100%)
  - Installing doctrine/dbal (v2.9.2): Downloading (100%)
  - Installing doctrine/lexer (v1.0.1): Downloading (100%)
  - Installing doctrine/annotations (v1.6.0): Downloading (100%)
  - Installing doctrine/reflection (v1.0.0): Downloading (100%)
  - Installing doctrine/collections (v1.6.0): Downloading (100%)
  - Installing doctrine/persistence (v1.1.0): Downloading (100%)
  - Installing doctrine/inflector (v1.3.0): Downloading (100%)
  - Installing doctrine/common (v2.10.0): Downloading (100%)
  - Installing doctrine/orm (v2.6.3): Downloading (100%)
  - Installing symfony/polyfill-ctype (v1.11.0): Downloading (100%)
  - Installing symfony/yaml (v4.2.4): Downloading (100%)
  - Installing guzzlehttp/promises (v1.3.1): Downloading (100%)
  - Installing guzzlehttp/guzzle (6.3.3): Downloading (100%)
  - Installing influxdb/influxdb-php (1.14.7): Downloading (100%)
  - Installing symfony/event-dispatcher (v4.2.4): Downloading (100%)
  - Installing andig/dbcopy (1.3): Downloading (100%)
  - Installing andig/php-shunting-yard (1.0.2): Downloading (100%)
  - Installing react/promise-stream (v1.1.1): Downloading (100%)
  - Installing ringcentral/psr7 (1.2.2): Downloading (100%)
  - Installing react/http (v0.8.4): Downloading (100%)
  - Installing http-interop/http-middleware (0.5.0): Downloading (100%)
  - Installing psr/log (1.1.0): Downloading (100%)
  - Installing symfony/debug (v4.2.4): Downloading (100%)
  - Installing symfony/http-kernel (v4.2.4): Downloading (100%)
  - Installing paragonie/random_compat (v9.99.99): Downloading (100%)
  - Installing monolog/monolog (1.24.0): Downloading (100%)
  - Installing react/child-process (v0.5.2): Downloading (100%)
  - Installing symfony/process (v4.2.4): Downloading (100%)
  - Installing php-pm/php-pm (1.0.5): Downloading (100%)
  - Installing php-pm/httpkernel-adapter (1.0.6): Downloading (100%)
  - Installing webpatser/laravel-uuid (3.0.2): Downloading (100%)
Package http-interop/http-middleware is abandoned, you should avoid using it. Use http-interop/http-server-middleware instead.
Writing lock file
Generating autoload files
~

volkszaehler.org is not configured yet. creating new config from sample config file.
mysql root user? [root]
mysql root password? [] raspberry
mysql database? [volkszaehler]
mysql admin to volkszaehler database? [vz-admin]
mysql admin password? [] secure
mysql user? [vz]
mysql password? [demo]

create volkszaehler.org database and admin user? [y]
creating database volkszaehler...
creating db user vz-admin...
creating database schema...
~/volkszaehler.org ~

 !
 ! [CAUTION] This operation should not be executed in a production environment!
 !

 Creating database schema...


 [OK] Database schema created successfully!



 Processing entity "Volkszaehler\Model\Aggregate"
 Processing entity "Volkszaehler\Model\Entity"
 Processing entity "Volkszaehler\Model\Channel"
 Processing entity "Volkszaehler\Model\Property"
 Processing entity "Volkszaehler\Model\Aggregator"
 Processing entity "Volkszaehler\Model\Data"

 Proxy classes generated to "/home/pi/volkszaehler.org/lib/Model/Proxy"
~

create volkszaehler.org database user? [y]
creating db user vz with proper rights...

allow channel deletion? [n] y
granting db user vz delete rights...

insert demo data in to database? [n]

Das Script fragt, was es wohin installieren soll.

Webserver per PPM (empfohlene Methode)

Der PPM-Webserver auf Basis von PHP läuft wesentlich Performanter als Apache2 und ist gerade auf schwacher Hardware wie RaspberryPi zu empfehlen.

  1. Systemd Service einrichten sudo nano /etc/systemd/system/middleware.service
    [Unit]
    Description=Volkszaehler.org Middleware
    After=syslog.target network.target
    Requires=
    
    [Service]
    ExecStart=/usr/bin/php /var/www/volkszaehler.org/vendor/bin/ppm start -c /var/www/volkszaehler.org/etc/middleware.json -cgi-path=/usr/bin/php
    ExecReload=/bin/kill -HUP $MAINPID
    StandardOutput=journal
    Restart=always
    
    [Install]
    WantedBy=multi-user.target 
  2. Server Konfiguration anpassen
    1. nano ~/volkszaehler.org/etc/middleware.json
    2. ändern: „port“: 80,
    3. ändern: „static-directory“: „/var/www/volkszaehler.org/htdocs“,
  3. Middleware Weiterleitung url anpassen nano ~/volkszaehler.org/htdocs/js/options.js
    title: 'Local (default)',
    url: ''
    //live: 8082
  4. Systemd Service bei boot aktiveren sudo systemctl enable middleware
  5. Systemd Service starten sudo systemctl start middleware

Alternative: Apache installieren (unter Debian "Jessie" und "Stretch")

  • Pakete installieren sudo apt-get install apache2 libapache2-mod-php7.1
  • mod_rewrite aktivieren: sudo a2enmod rewrite
  • Default VirtualHost bearbeiten: sudo nano /etc/apache2/sites-enabled/000-default.conf

' In der Datei, neben < DocumentRoot > eintragen:

 /var/www/volkszaehler.org/htdocs/
  • Apache Config bearbeiten um Rewrite zu erlauben: sudo nano /etc/apache2/apache2.conf
  • In der Datei den Abschnitt suchen:
<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>
  • in AllowOverride All AuthConfig ändern.

Nach dem editieren und abspeichern der Datei sudo systemctl restart apache2 ausführen.

Sollte es zu einem PHP Fehler beim Anlegen der Datenbank kommen versucht mal Doctrine per Hand zu Installieren.

Manuelle Installation

Download der volkszaehler.org Skripte

Download der Skripte aus dem git Repository:

git clone git://github.com/volkszaehler/volkszaehler.org.git ~/volkszaehler.org
sudo ln -sf ~/volkszaehler.org /var/www/volkszaehler.org
sudo chown -R www-data /var/www/volkszaehler.org

Apache konfigurieren

  • mod_rewrite aktivieren:
sudo a2enmod rewrite
  • Default VirtualHost bearbeiten:
/etc/apache2/sites-enabled/000-default:
    DocumentRoot /var/www/volkszaehler.org/htdocs/
  • unter <Directory /var/www/>:
AllowOverride FileInfo Limit Options Indexes Authconfig

Alternativ: nginx konfigurieren

server {
        listen 80;
        listen [::]:80;
        server_name volkszaehler.org;

        root /var/www/volkszaehler.org/htdocs;

        index index.php index.html;

        location / {
                try_files $uri $uri/ =404;
        }
        location ~ \.php {
                include snippets/fastcgi-php.conf;
        #       # With php5-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
                # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
        }
}

Wichtig ist dass in der config in der Zeile „location ~ \.php {“ kein $-Zeichen hinter dem PHP steht. Siehe Mail Archiv

Installation der benötigten Module

Zunächst PHP Paketmanager Composer von getcomposer.org installieren
cd /tmp
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer
Ahängigkeiten laden und installieren (v.a. Doctrine)
cd /var/www/volkszaehler.org/ # Anmerkung: ansonsten wird die Datei "composer.json" nicht gefunden; Fehlermeldung: "Composer could not find a composer.json file..."
composer install

Konfiguration der Middleware

cd /var/www/volkszaehler.org/etc/
cp volkszaehler.conf.template.php volkszaehler.conf.php
edit volkszaehler.conf.php:
    $config['db']['host']               = 'localhost';
    $config['db']['user']               = 'vz';
    $config['db']['password']           = '<shhh!>';
    $config['db']['dbname']             = 'volkszaehler';

Alternativ wird die Installation in der Doctrine Dokumentation beschrieben. Falls du also Probleme bei der Installation haben solltest, kannst du dir hier noch ein paar Informationen holen.

Datenbank konfigurieren

  • Datenbank-User anlegen:
phpmyadmin:
    Home -> "Rechte" -> "Neuen Benutzer hinzufügen"
        Benutzername: vz
        Host: localhost
        Passwort: <shhh!>
        keine globalen Rechte vergeben!
        -> ok
oder:
    CREATE USER 'vz'@'localhost' IDENTIFIED BY '<shhhh!>';
  • Datenbank anlegen:
phpmyadmin
    Home -> "Datenbank anlegen", Name: "volkszaehler" -> "Anlegen"
oder:
    CREATE DATABASE `volkszaehler`;
  • Tabellen anlegen:
# cd /var/www/volkszaehler.org/
# php bin/doctrine orm:schema-tool:create
ATTENTION: This operation should not be executed in a production environment.

Creating database schema...
Database schema created successfully!
  • Demoinhalte importieren:
      Tabelle "entities" auswählen (unbedingt zuerst diese importieren!)
      "Importieren"; das Gleiche mit "properties" und "data"

oder:

      cd /var/www/volkszaehler.org/misc/sql
      cat entities.sql properties.sql data-demoset1.sql | mysql -uroot volkszaehler -p
  • Rechte setzen:
Datenbank "mysql", Tabelle "tables_priv":
    "Einfügen": 
        Host: "localhost"
        Db: "volkszaehler"
        User: "vz"
        Table_name: "data" (anschließend das Gleiche mit "entities", "entities_in_aggregator", "properties", "tokens"
        Table_priv: "select", "update" und "insert"
        
oder:
        GRANT select, update, insert ON volkszaehler.* TO vz@localhost;
  • Nun noch ein Passwort für den mysql-Administrator „root“ setzen und die Passwortdatenbank aktivieren:
mysqladmin password -u root "<neues, gutes passwort>"
mysqladmin reload -p

Aktualisierung der Middleware einschließlich des Frontends

Nachdem Volkszähler im Zuge der Installation eine Kopie des git Repositories erstellt, kann die Installation auch aus diesem Repository aktualisiert werden.

Eine Beschreibung findet sich im Kapitel zu git.

phpMyAdmin installieren

Für Vollzugriff auf die Volkszählerdatenbank über phpMyAdmin haben wir den User vz-admin. Standardpasswort: secure

MySQL-Superuser ist: root und das Standardpasswort: raspberry
phpMyAdmin-Superuser ist: phpmyadmin und das Standardpasswort: raspberry

Debian Stretch

sudo apt-get install phpmyadmin

Nach Installation der nötigen Pakete wird das Konfigurationsscript gestartet. Es konfiguriert Apache und fragt nach einem Passwort für den neu anzulegenden User phpmyadmin.

Wenn kein Passwort vergeben wird kann das Fehlfunktionen zur Folge haben

Auch Apache wird automatisch neu gestartet.

Unter Stretch kann man sich in MySQL nur als root anmelden wenn man lokal als root agiert (sudo).
Von und für phpMyAdmin ist deswegen der User phpmyadmin angelegt worden.

Um dem neuen User volle Adminrechte zu gewähren:

sudo mysql -uroot -praspberry --execute "grant all privileges on *.* to 'phpmyadmin'@'localhost' with grant option"
software/middleware/installation.1553511467.txt.gz · Zuletzt geändert: 2019/03/25 11:57 von jau