Installing Libwebsockets - STwilight/Pi-Box GitHub Wiki

This project needs Libwebsockets library to be installed for secure connections establishing via WebSocket.

Installation of Libwebsockets library contains several steps:

Building and installing OpenSSL library

We will build and install OpenSSL from sources.
For this we need to fetch latest source code from the official site.
In this example I used source code of 1.1.0f version.

Let's get archive with sources:
sudo wget https://www.openssl.org/source/openssl-1.1.0f.tar.gz

After that we need to untar fetched archive: sudo tar -xvzf openssl-1.1.0f.tar.gz.
And go to the containing folder: cd openssl-1.1.0f.

Now we need to configure OpenSSL building options:
sudo ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl.

When configuration process will be finished, we can run building via sudo make command.
If there are no errors, library can be installed using sudo make install command.
Now library is installed successfully.

Making symlinks for OpenSSL

Library's installation script does not making any symlinks, so we need to create them manually:
sudo ln -s /usr/local/openssl/lib/libssl.so.1.1 /lib/libssl.so.1.1
sudo ln -s /usr/local/openssl/lib/libcrypto.so.1.1 /lib/libcrypto.so.1.1

After that we can check library version by running command:
/usr/local/openssl/bin/openssl version

Installing CMake

We need a CMake of version 2.8 or greater for Libwebsockets library compilation.
It can be simply installed via sudo apt-get install cmake -y command.

Building and installing Libwebsockets library

Libwebsockets sources are available from official repository and we can fetch them:
sudo git clone https://github.com/warmcat/libwebsockets.git /home/libwebsockets

After that we have to enter source codes directory and create there 'build' directory:
cd /home/libwebsockets
sudo mkdir build

Than we must enter the folder, that we have created, and start process of generating build files:
cd build
sudo cmake .. -DOPENSSL_ROOT_DIR=/usr/local/openssl -DOPENSSL_LIBRARIES=/usr/local/openssl

Ensure, that you have specified the same path, that was used for OpenSSL's building options configuration.
When CMake will finish their work, the library's sources can be built and installed via following commands:
sudo make
sudo make install

Generating self-signed certificate for testing

Note: This step is optional and only needed, if you want to run test example of secure WebSocket server.

For running example of WebSocket secure server, you need to generate the self-signed certificate, that must be located in '/usr/local/share/libwebsockets-test-server' folder. It can be done using next commands:
cd /usr/local/share/libwebsockets-test-server
sudo openssl req -x509 -newkey rsa:4096 -keyout libwebsockets-test-server.key.pem -out libwebsockets-test-server.pem -days 365

Then you must follow to the instructions of the OpenSSL's master.
When certificate and key was generated, WSS example can be launched by simple command:
sudo libwebsockets-test-server --ssl

For more details, please refer to the Libwebsocket's test applications description article.