How to Integrate Collabora Online Server with Nextcloud on Ubuntu 16.04

This tutorial is going to show you how to install Collabora online server on Ubuntu 16.04 and then integrate it with an existing Nextcloud server.

Collabora online is a self-hostable and LibreOffice-based open source online office suite. Its features includes:

  • Basic editing
  • High fidelity, WYSIWYG rendering
  • Supports DOC, DOCX, PPT, PPTX, XLS, XLSX, ODF document format
  • Import and view Visio, Publisher and 100+ more
  • Shared Editing

Prerequisites

It’s assumed that you have already set up a Nextcloud server which can be on any Linux distribution. If you use Ubuntu 16.04 or Arch Linux, then you can check out the following easy-to-understand guides.

The Collabora Online server and Nextcloud server can be on the same machine or on two different machines. This tutorial shows how to install Collabora online server on Ubuntu 16.04 using a Docker image built by Collabora and Nextcloud. Then integrate it with an existing Nextcloud server.

Step 1: Install Docker on Ubuntu 16.04

If you want the latest Docker version, you can install Docker from Docker’s APT repository. For simplicity, this tutorial install Docker from the default Ubuntu software repository. Fire up a terminal window (CTRL+ALT+T) and run the following command to install Docker from Ubuntu repository.

sudo apt update
sudo apt install docker.io

Once installed, the Docker daemon should be automatically started. You can check its status with:

systemctl status docker

If it’s not running, then start the daemon with this command:

sudo systemctl start docker

And enable autostart at boot time:

sudo systemctl enable docker

Step 2: Install and Run Collabora Online Server with Docker

Execute the following command to pull the latest Collabora Online Development Edition image from Docker hub.

sudo docker pull collabora/code

collabora online docker image

Then run this docker container. Replace nextcloud\\.your-domain\\.com with your nextcloud server domain (preserving backslash).

sudo docker run -t -d -p 127.0.0.1:9980:9980 -e 'domain=nextcloud\\.your-domain\\.com' --restart always --cap-add MKNOD collabora/code

The Collabora online server will be listening on port 9980 of localhost (127.0.0.1) as can be shown by issuing this command:

sudo netstat -lnpt

collabora online server daemon

Step 3: Set up Reverse Proxy

Nextcloud server requires a TLS/SSL certificate on the Collabora online server, so we will need to create a virtual host, give the virtual host a domain name, install TLS/SSL certificate and set up a reverse proxy. We can use either Apache or Nginx to achieve this.

First let us see how to do this with Apache.

Set up Apache Virtual Host

Install Apache web server with the following command:

sudo apt install apache2

Run the following command to create an Apache virtual host file. Replace the domain name with your actual domain name for Collabora online server. Don’t forget to create an A record for this domain name.

sudo nano /etc/apache2/sites-available/office.your-domain.com.conf

Put the following text into the file.

<VirtualHost *:80>
 ServerName office.your-domain.com
 </VirtualHost>

Save and close the file. Enable this virtual host with the following command:

sudo a2ensite office.your-domain.com.conf

Then restart Apache.

sudo systemctl restart apache2

HTTPS helps us prevent man-in-the-middle attack and password sniffing. We can obtain a free TLS/SSL certificate from Let’s Encrypt CA. First Let’s install the certbot client. The client is still named letsnecrypt in Ubuntu repository. The following command will install the client and apache plugin.

sudo apt install letsencrypt python-letsencrypt-apache

Now issue the following command to obtain a free TLS/SSL certificate. Replace the red-colored text with your actual data.

sudo letsencrypt --apache --agree-tos --email your-email-address -d office.your-domain.com

You will be asked to choose easy or secure. It’s recommended to choose secure so that all http requests will be redirected to https.

let's encrypt apache

Once you hit the OK button, a free TLS/SSL certificate is obtained and installed on the Apache virtual host.

Set up Apache Reverse Proxy

To be able to proxy traffic using Apache, run the following commands to enable each of these Apache modules.

sudo a2enmod proxy

sudo a2enmod proxy_wstunnel

sudo a2enmod proxy_http

sudo a2enmod ssl

Then run the following command to edit the new virtual host file created by Let’s Encrypt ( certbot ) client.

sudo nano /etc/apache2/sites-enabled/office.your-domain.com-le-ssl.conf

Add the green text to this file so it looks like the following.

<IfModule mod_ssl.c>
<VirtualHost *:443>
  ServerName office.your-domain.com

  SSLCertificateFile /etc/letsencrypt/live/office.your-domain.com/fullchain.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/office.your-domain.com/privkey.pem
  Include /etc/letsencrypt/options-ssl-apache.conf

  # Encoded slashes need to be allowed
  AllowEncodedSlashes On

  # Container uses a unique non-signed certificate
  SSLProxyEngine On
  SSLProxyVerify None
  SSLProxyCheckPeerCN Off
  SSLProxyCheckPeerName Off

  # keep the host
  ProxyPreserveHost On

  # static html, js, images, etc. served from loolwsd
  # loleaflet is the client part of LibreOffice Online
  ProxyPass /loleaflet https://127.0.0.1:9980/loleaflet retry=0
  ProxyPassReverse /loleaflet https://127.0.0.1:9980/loleaflet

  # WOPI discovery URL
  ProxyPass /hosting/discovery https://127.0.0.1:9980/hosting/discovery retry=0
  ProxyPassReverse /hosting/discovery https://127.0.0.1:9980/hosting/discovery

  # Main websocket
  ProxyPassMatch "/lool/(.*)/ws$" wss://127.0.0.1:9980/lool/$1/ws

  # Admin Console websocket
  ProxyPass /lool/adminws wss://127.0.0.1:9980/lool/adminws

  # Download as, Fullscreen presentation and Image upload operations
  ProxyPass /lool https://127.0.0.1:9980/lool
  ProxyPassReverse /lool https://127.0.0.1:9980/lool

</VirtualHost>
</IfModule>

Save and close the file. Then restart Apache web server.

sudo systemctl restart apache2

Now let’s see how to achieve the same results with Nginx. 

Set up Nginx Virtual Host

Install Nginx on Ubuntu 16.04 with the following command:

sudo apt install nginx

Create a virtual host file. Replace the domain name with your actual domain name for Collabora online server. Don’t forget to create an A record for this domain name.

sudo nano /etc/nginx/conf.d/office.your-domain.com.conf

Put the following text into the file.

server {
  listen 80;
  server_name office.your-domain.com;

  root /usr/share/nginx/office;
}

Save and close the file. Create a directory for this virtual host.

sudo mkdir /usr/share/nginx/office

And let the Nginx user (www-data) be the owner of this directory.

sudo chown www-data:www-data /usr/share/nginx/office -R

Reload Nginx server.

sudo systemctl reload nginx

Now let’s obtain a free TLS certificate from Let’s encrypt. Install certbot client with:

sudo apt install letsencrypt

Then use the webroot plugin to obtain the certificate. Replace red text with your actual data.

sudo letsencrypt certonly --webroot --email your-email-address -d office.your-domain.com -w /usr/share/nginx/office/

You will see the following text indicating that you have successfully obtained a TLS certificate. Your certificate and chain have been saved at /etc/letsencrypt/live/office.your-domain.com/ directory.

Let's encrypt free tls certificate

Setting up Nginx reverse Proxy

Edit the virtual host file.

sudo nano /etc/nginx/conf.d/office.your-domain.com.conf

Change the configuration to the following.

server {
  listen 443 ssl;
  server_name office.your-domain.com;
  root /usr/share/nginx/office;

  ssl_protocols TLSv1.1 TLSv1.2;
  ssl_certificate /etc/letsencrypt/live/office.your-domain.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/office.your-domain.com/privkey.pem;

  # static files
  location ^~ /loleaflet {
    proxy_pass https://localhost:9980;
    proxy_set_header Host $http_host;
  }

  # WOPI discovery URL
  location ^~ /hosting/discovery {
    proxy_pass https://localhost:9980;
    proxy_set_header Host $http_host;
  }

  # websockets, download, presentation and image upload
  location ^~ /lool {
    proxy_pass https://localhost:9980;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $http_host;
  }
}

Save and close the file. Then test nginx configuration and reload Nginx.

sudo nginx -t

sudo systemctl reload nginx

Final Step: Connect Nextcloud to Collabora Online Server

In order to connect your Nextcloud server to Collabora online server, first you need to enable experimental apps in Nextcloud.

In your Nextcloud dashboard, go to Apps,

nextcloud apps

Then click the gear icon on the bottom-left corner and check Enable experimental apps.

 collabora online server experimental app

Next, click Productivity tab on the left, find the Collabora Online connector app and click Enable button.

nextcloud collabora online connector

Update:  Nextcloud might have changed the Apps interface. If you can’t find Productivity tab, then go to Not Enabled tab, find and enable Collabora Online connector app. The Collabora Online connector app might also changed its name to Collabora Online.

Finally, go to Nextcloud admin page. Click Additional settings tab on the left. Scroll down to Collabora Online section and enter the domain name of your Collabora online server including https:// prefix. Don’t forget to click Apply button.

collabora online

Now you should see a new Office app from the drop-down menu.

collabora online app

And you are able to create Word, spreadsheet and presentation documents right from your Nextcloud server.

collabora online nextcloud

That’s it!

I hope this tutorial helped you install, run Collabora online server on Ubuntu 16.04 and integrate it with Nextcloud. As always, if you found this post useful, then subscribe to our free newsletter.You can also follow us on Google+Twitter or like our Facebook page.

Rate this tutorial
[Total: 7 Average: 4.4]
  • Jon

    Thank you for creating this. Excellent instructions. 🙂

  • i have wrote the same Tutorial in German. I have problems to connect to Documents. Do you have the same issue?

    • Sometimes it can take a minute to open a new word document in Nextcloud. The browser’s debug console says it failed to load SourceMap and a png file can not be found in Collabora online server (404 error).

      I think it’s because the docker image is a development version of Collabora online, not a stable one.

  • Vincent Van Houtte

    Ji, thx for the excellent writeup – I do have an issue finding the ‘Collabora Online Connector’ app in the Nextcloud

    Apps-section… I am fully updated with the latest version of Nexcloud (v10.0.1 iirc). Could it be that this connector is not available for this version yet?

    • Vincent Van Houtte

      Sorry, false alarm – suddenly the ‘productivity’-category is populated and the app is there. Thx!

  • pajd

    Thank you for you tutorial. When activating nginx, I encounter this message.

    root@***:~# sudo systemctl reload nginx
    nginx.service is not active, cannot reload.
    root@***:~# sudo systemctl start nginx
    Job for nginx.service failed because the control process exited with error code. See “systemctl status nginx.service” and “journalctl -xe” for details.
    root@***~# sudo systemctl reload nginx
    nginx.service is not active, cannot reload.
    root@***:~# sudo systemctl status nginx.servic
    ● nginx.servic.service
    Loaded: not-found (Reason: No such file or directory)
    Active: inactive (dead)

    Why is this showing even though I installed nginx?

    • Check out the log to see what caused this problem.

       sudo journalctl -xe

      or

       sudo less /var/log/nginx/error.log
      • pajd

        Thank you for your quick answer.

        Here is what I get:

        Nov 19 11:15:04 vps338912 kernel: [UFW BLOCK] IN=ens3 OUT= MAC=fa:16:3e:1f:31:98:fe:01:d6:d5:05:4e:08:00 SRC=85.214.201.198 DST=51.254.120.238 LEN=60 TOS=0x00 PREC=0x00 TTL=55 ID=21

        2016/11/19 11:08:25 [emerg] 581#581: listen() to [::]:80, backlog 511 failed (98: Address already in use)
        2016/11/19 11:08:25 [emerg] 581#581: still could not bind()
        /var/log/nginx/error.log (END)

        I added Nginx on ufw (sudo ufw allow in “Nginx Full”), yet it does not seem to help. How can I allow Nginx traffic?

        • listen() to [::]:80, backlog 511 failed (98: Address already in use)

          This line tells you that port 80 is already is use by another process, so Nginx can’t listen on port 80. Have you installed Apache on your server? If that’s so, then you may want to use Apache rather than Nginx to set up the reverse proxy.

          • pajd

            Thank you. Of course, you are right. Followed all the steps with Apache.

            I get this message when I try to use collabora in NC: Collabora Online unknown error: Client error response [url] https://office.***.***/hosting/discovery [status code] 404 [reason phrase] Not Found

            Only glitch when I set all up was that the file /etc/apache2/sites-enabled/office.***.***.conf was not present even though the process with Letsencrypt worked fine. I therefore created it. Could the problem come from there?

          • In this case, check out Apache error log.

            sudo less /var/log/apache2/error.log
          • pajd

            [Sat Nov 19 13:08:50.894381 2016] [ssl:warn] [pid 7794] AH01909: ***.***:443:0 server certificate does NOT include an ID which matches the server name
            [Sat Nov 19 13:08:50.970420 2016] [ssl:warn] [pid 7795] AH01909: ***.***:443:0 server certificate does NOT include an ID which matches the server name
            [Sat Nov 19 13:08:50.975775 2016] [mpm_prefork:notice] [pid 7795] AH00163: Apache/2.4.18 (Ubuntu) OpenSSL/1.0.2g configured — resuming normal operations
            [Sat Nov 19 13:08:50.975820 2016] [core:notice] [pid 7795] AH00094: Command line: ‘/usr/sbin/apache2’

          • Looks like the domain name in TLS certificate does not match the server name used in your Apache virtual host file.

          • pajd

            I redid all the steps. After issuing the certificates, I tried to edit
            /etc/apache2/sites-enabled/office.***.***-le-ssl.conf as you describe, but it does not exist. Instead I have office.***.***.conf . What did I miss?

          • That’s a bit weird. The /etc/apache2/sites-enabled/office.***.***-le-ssl.conf file should be created by Let’s Encrypt (certbot) client after the certificate is obtained. Are you sure the certificate is sucessfully obtained and can you visit the https version of your domain name in browser?

            You may want to manually create this file and put the necessary directives into the file.

          • pajd

            Thanks for your precious help.

            Certificate seems to work fine:
            Congratulations! Your certificate and chain have been saved at
            /etc/letsencrypt/live/office.***.***/fullchain.pem. Your cert
            will expire on 2017-02-17. To obtain a new version of the
            certificate in the future, simply run Let’s Encrypt again.

            I configured the A record for office.***.*** to my main domain ***.*** and it loads successfully the Apache2 Ubuntu Default Page.

            Did I miss something?

          • Try manually creating this file and put the necessary directives into the file. Then restart Apache to see if it will work.

          • pajd

            Did this and it worked when i restarted Apache.

            But when I open office in NextCloud, I still get the error message:

            Collabora Online unknown error: Client error
            response [url] https://office.***.***/hosting/discovery [status code]
            404 [reason phrase] Not Found

            Please contact the “https://office.***.***” administrator.

          • Hi, pajd. I encountered the same error just a while ago. It’s because the docker container wasn’t running. You can use the following command to check the status of docker containers.

            sudo docker ps

            Use the following command to run the collabora docker container. Replace nextcloud\.your-domain\.com with your nextcloud server domain (preserving backslash).

            sudo docker run -t -d -p 127.0.0.1:9980:9980 -e ‘domain=nextcloud\.your-domain\.com’ –restart always –cap-add MKNOD collabora/code

            You may need to stop a non-responsive docker container with

             sudo docker stop container-id
          • pajd

            Thank you for your tip, Xiao Guoan. Unfortunately, it did not help solve the issue…

  • john

    hello,

    i properly installed nextCloud and collabora. i can access my web using https. but when when i click on APP its not showing productivity tab.
    please help me what will be the issue.

    • Nextcloud might have changed the Apps interface. Just enable experimental apps and find Collabora Online connector app in the Not Enabled tab. Then click the enable button.

      The Collabora Online connector app might also changed its name to Collabora Online.