Changing port number on openHAB 2.0

Just tested it on my Mac and it works. I would expect the same behaviour on a RPi.
You might not be able to use any port below 1024 though as those are priviledged.

I’m running openhab as sudo so normally it should have root privileges.
I will try to change to an other port above 1024 to check if that works

ENV Variable OPENHAB_HTTP_PORT didnt work for me either. I used the XML file.

Okey than i’m going to try the xml way

I was looking for this info too. The 2.0 b3 obeys the port config in /etc/defaults/openhab2 file:


I had to change it, as the 8080 was already taken by another app, motion. Maybe this helps someone looking for info, and would end up into docs. Note, it must have “export” in it.

Hello, I have fresh installation on PC with Win7. The port 8080 is blocked and I need to change to any else. In previously version of OpenHAB I used 1883 and its worked fine.

In tutorial here:
is note: export OPENHAB_HTTP_PORT=8011
But where??? I tried to change start.bat, but no change…
Thank you for your help.


The export statement is for linux users. I believe in windows, you’ll need to add a system variable to define the openhab port. Go to System->System Variables and add a new one with the same syntax as the others already there.

For anyone else coming across this, I have just setup OH2_b4 on an RPi3 and found I had to change the HTTP_PORT value near the top of /usr/share/openhab2/runtime/karaf/bin/setenv

The export OPENHAB_HTTP_PORT option in /etc/defaults/openhab2 didn’t seem to work for some reason, but I may have missed something.

Hope that helps.


1 Like

I managed to change the ports on OH2 on a RPi3 by editing /etc/default/openhab2
sudo nano /etc/default/openhab2
add the lines

DONT use export, it will not work

elysiandc solution worked but the file was changed in every update

Hope that helps


looks like for oh2 beta 5 the right (?) place to change port settings is /opt/openhab2/runtime/bin/setenv

Kindly let me know if there is an easier, e.g. more elegant way to adapt ports

That would work but @Fivos_G’s answer above you should be more appropriate, since that file won’t get reset each upgrade.

@Benjy valid point taken.

However at manual installation there is no file /etc/defaults/openhab2, neither under ./runtime/etc nor at ./userdata/etc.

Tried to create ./userdata/etc/defaults/openhab2 and add
but it did not work

Finally what worked was to add in: /opt/openhab2/ following lines:

I got the same problem.

I installed openhab2 beta via apt-get on my raspsi (still wheezy, but up to date)
Port 8080 is already taken.

I get this error:

2017-01-17 00:28:50.835 [ERROR] [.service.internal.HttpServiceStarted] - Could not start the servlet context for context path [] Die Adresse wird bereits verwendet

I added the parameters to /etc/default/openhab2.


But the error still hapens.


should not be necessary. I just tested setting OPENHAB_HTTP_PORT and OPENHAB_HTTPS_PORT as environment variables on a normal installation (not APT!) and all works as expected.

I therefore assume that the problem is with the apt installation only. @Benjy did you test this yourself already?


was there by default.

I just added some echos to debug.

in /usr/share/openhab2/runtime/bin/setenv

echo "HTTP: $OPENHAB_HTTP_PORT" >> /tmp/oh_port.txt

I get an emtpy value everytime.

in /etc/default/openhab2

echo "HTTP2: $OPENHAB_HTTP_PORT" >> /tmp/oh_port.txt

I get the correct value.

When starting or stopping the service I get this:

HTTP2: 9090

For some reason the value (or the variable) gets deleted or is not accessible in the setenv script.

Maybe I can debug further in the evening.

I’ll have a look too.

@christoph_wempe, what happens if you run:

systemctl --system daemon-reload
sudo service openhab2 restart

after you change /etc/default/openhab2?

@Kai @Benjy I’d suggest to add commented examples into the default file

Will do when I know what the correct ones are! :wink:

Cannot do that.
I am still running respbian wheezy on my test system. :frowning:

sudo: systemctl: command not found