How can I install openHAB Cloud on local Ubuntu 20.04

Hi,

I could use help to install the openHAB Cloud on an Ubuntu 20.04 VM. Instead of LetsEncrypt I tried to use mkcert.

sudo hostname openhab-cloud
hostname --fqdn
openhab-cloud

At first I executed

sudo apt update && sudo apt upgrade
sudo apt install build-essential redis-server mongodb nginx python git certbot python-certbot-nginx
sudo apt-get install python-software-properties

To avoid the following error, I installed NodeJS version 12.22.1:

error: uncaughtException: Cannot find module ‘bcrypt’
Error: Cannot find module ‘bcrypt’
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object. (/var/www/hostname.de/openhab-cloud/models/userdevice.js:3:14)
at Module._compile (module.js:571:32)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object. (/var/www/hostname.de/openhab-cloud/fcm-xmpp.js:8:20)
at Module._compile (module.js:571:32)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)

So I installed NodeJS like you can see here:

sudo apt update
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt install nodejs

I tried to use certbot but I does not work because of DNS problems…

Obtaining a new certificate
Performing the following challenges:
http-01 challenge for openhab-cloud.hs-furtwangen.de
Waiting for verification...
Challenge failed for domain openhab-cloud.hs-furtwangen.de
http-01 challenge for openhab-cloud.hs-furtwangen.de
Cleaning up challenges
Some challenges have failed.

IMPORTANT NOTES:
 - The following errors were reported by the server:

   Domain: openhab-cloud.hs-furtwangen.de
   Type:   dns
   Detail: DNS problem: NXDOMAIN looking up A for openhab-cloud.hs-furtwangen.de

Then I tried mkcert:

sudo apt install libnss3-tools
wget https://github.com/FiloSottile/mkcert/releases/download/v1.1.2/mkcert-v1.1.2-linux-amd64
mv mkcert-v1.1.2-linux-amd64 mkcert
chmod +x mkcert
cp mkcert /usr/local/bin/

mkcert -install
sudo mkcert openhab-cloud.hs-furtwangen.de '*.openhab-cloud.hs-furtwangen.de' localhost 127.0.0.1 ::1

Then the nginx configuration:

sudo rm -r rm /etc/nginx/sites-enabled/default
sudo ln -s /etc/nginx/sites-available/openhab-cloud.hs-furtwangen.de /etc/nginx/sites-enabled/openhab-cloud.hs-furtwangen.de
sudo nano /etc/nginx/sites-available/openhab-cloud.hs-furtwangen.de

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name openhab-cloud.hs-furtwangen.de;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;
    server_name openhab-cloud.hs-furtwangen.de

    ssl on;
    ssl_certificate /root/.local/share/mkcert/rootCA.pem;
    ssl_certificate_key /root/.local/share/mkcert/rootCA-key.pem;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
    ssl_ecdh_curve secp384r1;
    ssl_session_cache shared:SSL:10m;
    ssl_session_tickets off;
    ssl_stapling on;
    ssl_stapling_verify on;
    resolver 8.8.8.8 8.8.4.4 valid=300s;
    resolver_timeout 5s;

    add_header Strict-Transport-Security "max-age=63072000; includeSubdomains";
    add_header X-Frame-Options DENY;
    add_header X-Content-Type-Options nosniff;

    root /var/www/openhab-cloud.hs-furtwangen.de;
    index index.html index.htm;
    location ~ /.well-known {
        allow all;
    }
}

After that

sudo nginx -t
sudo systemctl restart nginx or sudo systemctl reload nginx

I think I should at first fix following:

curl openhab-cloud.hs-furtwangen.de
curl: (6) Could not resolve host: openhab-cloud.hs-furtwangen.de

curl openhab-cloud
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.18.0 (Ubuntu)</center>
</body>
</html>

Then I tried to install openHAB-Cloud:

cd ~
git clone https://github.com/openhab/openhab-cloud.git
sudo ln -s /var/www/openhab-cloud.hs-furtwangen.de /home/openhabcloud/openhab-cloud
cd ~/openhab-cloud
npm install
cp config-development.json config.json

Then I changed the config.json with nano config.json

{
    "system": {
        "host": "openhab-cloud.hs-furtwangen.de",
        "port": "443",
        "protocol": "https",
        "logger" : {
            "dir": "./logs",
            "maxFiles" : "7d",
            "level" : "debug",
            "morganOption" : "dev"
          }
    },
    "express":{
      "key" : "some express key"
    },
    "redis": {
        "host": "127.0.0.1",
        "port": "6379"
    },
    "mailer": {
        "host" : "somehost",
        "port": 465,
        "secureConnection": true,
        "user": "someuser",
        "password": "somepass",
        "from": "<your-mail>"
    },
    "gcm" : {
      "jid": "something@gcm.googleapis.com",
      "password": "password"
    },
    "apn" : {
      "team": "PB1234567",
      "keyId": "BLABLA1",
      "host": "api.development.push.apple.com",
      "defaultTopic": "es.spaphone.openhab",
      "signingKey": "certs/aps/AuthKey.p8"
    },
    "ifttt" : {
      "iftttChannelKey" : "key",
      "iftttTestToken" : "token"
    },
    "legal": {
        "terms" : "",
        "policy": ""
    }
}

I removed the line with mongodb because there was nothing configured yet. Also I remove a password for redis.

Then I run sudo node app.js.

{"errno":-2,"syscall":"open","code":"ENOENT","path":"certs/aps/AuthKey.p8"}

Sadly the page is empty.

However, I’m missing an explanation in this tutorial either way on how to properly set up mongodb accordingly or redis as well.

I think a little bit this could help:

(there as example the part with mongodb should be sufficiently explained.)

The bottom line, though, is that I would have to get the system to work like this first. Any functionality is still missing here. Neither by localhost I could reach it, as otherwise by URL.

On https://[my-ip] I receive:

403 Forbidden
nginx/1.18.0 (Ubuntu)

The URL http://[[my-ip] will forward to https://openhab-cloud.hs-furtwangen.de/ which says “Page not found”.

I think there is more than one thing misconfigured here. So besides config.json I would have to adjust the nginx configuration as well.

As far as I understand the domain openhab-cloud.hs-furtwangen.de does not exist yet.
I would suggest to first cretae the domain to make sure you do not have a mixture of different root causes.

1 Like

Well it`s not public but it exist. This is one reason why I can not use certbot.

Well it`s not public but it exist. This is one reason why I can not use certbot.

It doesn’t seem to exist for the system you’re running those commands on though.

curl -I openhab-cloud would at least show you where it is trying to redirect you to - where it thinks its base URL is. That might be a start

Then I tried to install openHAB:

Except the commands you pasted don’t install Openhab. Do you have that running somewhere? I’ve not used it yet, planning to do so, but am pretty certain openhab-cloud is a remote front-end / proxy service for an instance of OpenHAB, which is the actual automation platform

I still have to think about the first one. The second was simply a typo on my part. Of course I have openHAB somewhere else and wanted to install openHAB Cloud and not openHAB. I already know for what I need openHAB and for what I need openHAB Cloud, and what the difference is.