Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Howto install mosquitto with websockets

Install mosquitto with websockets

This is a guide how to install mosquitto on Ubuntu with websockets enabled.

It is more or less the same as explained in the article "Six Steps to install mosquitto 1.4.2 with websockets on debian whezy" http://www.xappsoftware.com/wordpress/2015/05/18/six-steps-to-install-mosquitto-1-4-2-with-websockets-on-debian-wheezy/comment-page-1/

Exceptions:

  1. mosquitto version 1.4.10 is used.
  2. libwebsockets-dev was installed using apt-get instead of building from source.

Install the dependencies

$ sudo apt-get update
$ sudo apt-get install build-essential python quilt python-setuptools python3
$ sudo apt-get install libssl-dev
$ sudo apt-get install cmake
$ sudo apt-get install libc-ares-dev
$ sudo apt-get install uuid-dev
$ sudo apt-get install daemon
$ sudo apt-get install libwebsockets-dev

Download mosquitto

$ cd Downloads/
$ wget http://mosquitto.org/files/source/mosquitto-1.4.10.tar.gz
$ tar zxvf mosquitto-1.4.10.tar.gz
$ cd mosquitto-1.4.10/
$ sudo nano config.mk

Edit config.mk

WITH_WEBSOCKETS:=yes

Build mosquitto

$ make
$ sudo make install
$ sudo cp mosquitto.conf /etc/mosquitto

Configure ports for mosquitto

Add the following lines to /etc/mosquitto/mosquitto.conf in the "Default Listener" section:

port 1883
listener 9001
protocol websockets

Add user for mosquitto

$ sudo adduser mosquitto

Reeboot computer

$ reboot

Run mosquitto

$ mosquitto -c /etc/mosquitto/mosquitto.conf
@jonathangaldino

This comment has been minimized.

Copy link

@jonathangaldino jonathangaldino commented Sep 14, 2017

Why Mosquitto 1.4.2? Not the latest? :D

@yacho0

This comment has been minimized.

Copy link

@yacho0 yacho0 commented Jan 8, 2018

I done this instructions of installation. Do you know why when i started broker mosquitto i dont get: Opening websockets listen socket on port 9001?

@jaybraun

This comment has been minimized.

Copy link

@jaybraun jaybraun commented Jun 5, 2018

Great work. Is there a version of these instructions for Fedora/RHEL/CentOS? I substituted some similar packages at the yum install . . . stages. During make, I encountered:

set -e; for d in lib client src; do make -C ${d}; done
make[1]: Entering directory `/home/braun/Downloads/mosquitto-1.4.10/lib'
cc -Wall -ggdb -O2  -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_SRV -c mosquitto.c -o mosquitto.o
In file included from mosquitto.c:33:0:
./mosquitto_internal.h:27:27: fatal error: openssl/ssl.h: No such file or directory
 #  include <openssl/ssl.h>
                           ^
compilation terminated.
make[1]: *** [mosquitto.o] Error 1
make[1]: Leaving directory `/home/braun/Downloads/mosquitto-1.4.10/lib'
make: *** [mosquitto] Error 2
@jaybraun

This comment has been minimized.

Copy link

@jaybraun jaybraun commented Jun 5, 2018

sudo yum install openssl-devel worked

@ZachW628

This comment has been minimized.

Copy link

@ZachW628 ZachW628 commented Jul 13, 2018

Thank you so much! This solution has helped me get mosquito to work with mqtt.js

@set09603

This comment has been minimized.

Copy link

@set09603 set09603 commented Jul 17, 2019

Worked great - but I needed to install these to make it work on a raspberry pi

sudo apt-get install xsltproc
sudo apt-get install docbook-xsl

Also, to make systemctl work...
sudo ln -s /usr/local/sbin/mosquitto /usr/sbin/

@mitul-srashtasoft

This comment has been minimized.

Copy link

@mitul-srashtasoft mitul-srashtasoft commented Dec 3, 2020

1606973623: mosquitto version 1.6.12 starting
1606973623: Config loaded from /etc/mosquitto/mosquitto.conf.
1606973623: Opening websockets listen socket on port 9001.
1606973623: Error: Unable to create websockets listener on port 9001.

@joko2020

This comment has been minimized.

Copy link

@joko2020 joko2020 commented Feb 24, 2021

Hello All,
I have Successfully install Mqtt with Instruction from http://linoxide.com/tools/setup-mosquitto-mqtt-server-ubuntu-16-04/
and running well.
but my mqtt server only listening on http protocol and I would like to use with websocket, and I follow Instruction Above
but my mqtt server won't start anymore with error Websockets support not available.
How to correct this issue

For Information I use
OS Ubuntu 16.04
mosquitto-1.4.9

@joko2020

This comment has been minimized.

Copy link

@joko2020 joko2020 commented Feb 24, 2021

Hello All,
I have Successfully install Mqtt with Instruction from http://linoxide.com/tools/setup-mosquitto-mqtt-server-ubuntu-16-04/ and running well.
but my mqtt server only listening on http protocol and I would like to use with websocket, and I follow Instruction Above
but my mqtt server won't start anymore with error Websockets support not available.
How to correct this issue

For Information I use
OS Ubuntu 16.04
mosquitto-1.4.9

Trying Clean installation of Ubuntu 16.04 and reinstall mosquitto with instruction above... now works fine for me.. thanks for tutorial

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment