Nextcloud on Synology DiskStation

Nextcloud installation on a Synology DiskStation with DSM 7.0

The new DSM 7 is here and here and the demand for Nextcloud is still very high. Synology offers its own cloud solution, Synology Drive, but it’s nowhere near as extensive and flexible as Nextcloud. Be it calendar and contact synchronization or the apps and web interface, there are many reasons for Nextcloud on a DiskStation. The article explains step by step how to install Nextcloud on a Synology NAS.

Preperation

Before we can start, check if you already have installed the Web Station, if not do so. You also need SSH access (to be found in the Control Panel under Terminal & SNMP) on your NAS (e.g. with PuTTY).
Important: If you are currently using Nginx as a web server, you have to switch to Apache HTTP Server 2.4 in the Web Station under General Settings > HTTP Backend Server. Nextcloud does not run under Nginx without configuring it beforehand. So far there is no working configuration for Synology in the community. You can set up a vhost for Nextcloud that uses Apache, then you can switch the rest of your DS back to Nginx.

You have to install following packages from the Package Center:

  • PHP 7.4
  • phpMyAdmin (only needed in case of installation issues)
  • Apache (2.4)
  • MariaDB 10

Open MariaDB 10 and tick “activate TCP/IP connection”.

Shared Folder

Creates a new shared folder to store the data. Nextcloud saves the data by default in the data folder under /web/Nextcloud. For security reasons, Nextcloud recommends creating the storage location outside of the /web folder. This also makes it easier to upgrade from Nextcloud at a later date. Nobody else should have access to the shared folder and even as an administrator you should only make changes there if they affect your Nextcloud installation. You should then make these changes via PuTTY as root, otherwise the ownership will change and Nextcloud can no longer access the folder/files. Create the shared folder via DSM > Control Panel > Shared Folder, if you create the folder via PuTTY, DSM does not recognize it and you cannot save it e.g. via Hyper Backup.

So that PHP can also access the shared folder, the path must be entered in open_basedir. Details can be found in the section “PHP Profile“.

Open PuTTY and connect to your DS. Log in as an administrator. To execute the commands as root enter sudo –i and press (Enter). Enter your administrator password again. Enter the following 2 commands so that Nextcloud or the user of the web server can also access it:

chown http:http /volume1/nextcloudData
chmod -R 777 /volume1/nextcloudData

PHP profile

Open the Web Station and create a new profile under Script Language Settings.

  1. Enter a name and a description.
  2. Select PHP 7.4.
  3. Tick “Enable PHP cache”.
  4. Tick “Customize PHP open_basedir” and enter /tmp:/var/services/tmp:/var/services/web. Now add the path to the shared folder created above (don’t forget the : ). It could look like following line: /tmp:/var/services/tmp:/var/services/web:/volume1/nextcloudData
  5. Activate following PHP extensions: bcmath, bz2, curl, ftp, gd, gmp, iconv, imagick, intl, mysqli, openssl, pdo_mysql, posix, sodium, ssh2, zip, zlib

Webserver Timeout

In DSM 7, Synology has set a general timeout for the Nginx as a proxy server (which is always active, even if you use Apache as a web server). However, the timeout no longer applies as soon as a virtual host is used. Anyone who knows my previous instructions for Nextcloud on Synology Diskstation will know where the timeout can be set under DSM 6. However, this does not work under DSM 7, because the entry conflicts with that of Synology.

  1. Connect to your NAS via SSH (e.g. PuTTY). Make the changes as root.
  2. Open the file /var/packages/WebStation/target/misc/VirtualHost-nginx-mustache in the editor.
vi /var/packages/WebStation/target/misc/VirtualHost-nginx-mustache
  1. Add the line proxy_read_timeout 3600s; in the block for Apache 2.2 or Apache 2.4 under include proxy.conf;. Make the change in the block that matches the Apache version used. You can also insert the line in both blocks.
  2. Save and close the file.
  3. First tests the Nginx configuration, then restarts the Nginx if the test is positive and then tests the config again:
nginx -t
synosystemctl restart nginx
nginx -t
Increase proxy timeout for vHosts.
Increase proxy timeout for vHosts.

The timeout for the proxy is now also increased when using virtual hosts. Now Apache can still time out. As with DSM 6, this can be fixed:

  1. Create the file /usr/local/etc/apache2X/sites-enabled/user.conf (as root).
vi /usr/local/etc/apache24/sites-enabled/user.conf
  1. Inserts the two lines TimeOut 3600 and ProxyTimeout 3600.
  2. Save and close the file.
  3. Restarts the Apache.

Installation

Download the latest version of Nextcloud as a .zip or .tar here. Upload the zip file to your DiskStation and extract it into the / web folder.

Now would be the right time to create the virtual host. You can also create the vHost after the installation.
To do this, select Web Service Portal in the Web Station and create a new entry with Create > Service Portal > Virtual Host.

  • Enter the host name under which you want to reach your Nextcloud. (The host name must exist and point to your DiskStation, more on this in this article.)
  • Select the ports to which the virtual host applies (usually 80/443).
  • Select the Nextcloud folder (/web/Nextcloud) as the document root.
  • Be sure to activate “HSTS” and “HTTP/2”, this ensures that all http access to your cloud is redirected to https. However, this requires a valid SSL certificate that was issued for the domain used. You can also find instructions for this in the previously linked article.
  • Select Apache 2.4 as web server and the previously created PHP profile.

Changes the privileges of the Nextcloud folder. It is best to create a script (text file with .sh extension) with the following content somewhere on the DiskStation:

#!/bin/bash
chown -R http:http /volume1/web/Nextcloud/
chmod -R 777 /volume1/web/Nextcloud/

To run the script as root, enter sudo –i and press Enter. Enter your admin password again. Now execute the script with sh /volume1/PathToScript/Installprivileges.sh. Instead of the script, you can also enter it line by line in the shell, but this is tedious because you have to change the privileges with each update.

Faulty database code

The Nextcloud setup automatically creates a database including tables and its own user. A syntax is used that causes problems with Synology’s version of MariaDB 10. In order for the installation to be carried out correctly, the problematic lines must be adjusted:

  1. Open (with PuTTY) the file /volumeX/web/Nextcloud/lib/private/Setup/MySQL.php
  2. Scroll almost to the end and look for the following line:
$this->dbPassword = $this->random->generate(30, ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER);
  1. Remove “, ISecureRandom::CHAR_DIGITS. ISecureRandom::CHAR_LOWER. ISecureRandom::CHAR_UPPER“, the result looks like this:
$this->dbPassword = $this->random->generate(30);
  1. Save and close the file.

Execute the installation assistant

Open Nextcloud in the browser. Make sure to use the address you have given for the virtual host (e.g. cloud.mydomain.com), if you have not configured a virtual host, use the IP, the name of the DiekStation or a domain that points to the DiskStation, followed by the Nextcloud- Directory (e.g. mynas.synology.me/Nextcloud) The address you use here is entered as a trusted domain during the installation. If you want to allow Nextcloud from other domains you have to enter this later in the config.php. This is the case if, for example, you want to access the cloud later via your own domain or DynDNS, but use the local name or the local IP of the DiskStation during installation.

Nextcloud Hub installation via browser

You can just ignore the error, you will only see it if your DiskStation does not have a 64bit CPU. Enter a username and password for the Nextcloud admin (the NC admin has nothing to do with the admin of the DiskStation). Under Storage & Database > Data Directory, /volumeX/web/nextcloud/data is entered by default, enter the path to the shared folder that you created earlier.

In the “Database” section you enter the MariaDB root user and the password. Alternatively, every user who has the right to create databases works. The user is only used for installation. A separate user is created that Nextcloud uses for operation. Assign a name for the database. Localhost is preset for the database domain, you still have to add the port. MariaDB 10 has port 3306 in DSM 7 and not 3307 as before. You can change the port in MariaDB 10.

Database details

New since Nextcloud 18 is the option to install recommended apps. If you want to use the integrated collaboration solution OnlyOffice, the app of the same name must be installed. You can leave out the apps at this point and install OnlyOffice afterwards. That makes sense, especially since you can only use Talk and OnlyOffice on DiskStations with an x86-CPU. The apps are very large, you don’t need them, save storage space and time and install e.g. Calendar and Contacts yourself afterwards.

Recommended Apps

Click the “Finish Setup” button to complete the setup. After a few moments the installation is complete and you should see the web interface.

Welcome tour of the web interface

Prevent issues

Before the installation, the installation script for the database had to be adapted. However, Nextcloud checks all files belonging to the Nextcloud installation for changes and issues a warning message. That could also interfere with the update. So open the file /volumeX/Nextcloud/lib/private/Setup/MySQL.php again and undo the changes. To do this, inserts the removed command segments again. Alternatively, you can also take the file from the Nextcloud zip and copy it over. But then adjust the privileges again.

Activate OnlyOffice

So much about “integrated”, even if you installed OnlyOffice during the setup, nothing works yet. Nevertheless, the integration is a step forward. So far, OnlyOffice had to be set up in a Docker container and Docker on DiskStation is no fun (the Synology version of Docker works differently than the official version). The integrated version of OnlyOffice makes Docker superfluous. But that doesn’t change the fact that OnlyOffice still requires an x86 CPU. If an ARM CPU is installed in your NAS, you can skip this section.

Not officially documented, another app has to be installed. Open the app store by clicking on your account on the right in the web interface and select + Apps there.

Some menues are a bit hidden

If you haven’t installed the recommended apps: Search for the ONLYOFFIC app. You can find it in the “Office & Text” section. Download and activate the app. Then look for the Community Document Server app, also under “Office & Text”. Download and activate the app.

The OnlyOffice app
The Community Document Server app

Synology is causing problems here again. One file is missing, but with a few extra steps we can get that under control.

  1. Download libstdc ++ 6 for Debian here.
  2. Unpack the following file: data.tar.\usr\lib\x86_64-linux-gnu\libstdc++.so.6.0.25
  3. Rename the file to libstdc++.so.6.
  1. Upload the file to your DiskStation.
  2. Copy the file with PuTTY:
cp <PathToFile> /volume1/web/nextcloud/apps/documentserver_community/3rdparty/onlyoffice/documentserver/server/FileConverter/bin
  1. Adjust the privileges and owner of the file. The owner must be http http. Use the commands given under “Installation“.
  1. Now go to the admin area: Right, on top, click on the account and select Settings. In the navigation area you can select ONLYOFFICE. Check whether the settings are available. The URL of your Nextcloud must be entered under “Service address”. If you use https – which I strongly recommend – the URL must correspond to the domain to which the SSL certificate is issued.
If the URL is correct OnlyOffice is ready to use

That’s it. If you click on a document in the “Files” area, OnlyOffice opens and you can edit it in the browser. If only the selection for a download appears, OnlyOffice is not active. If “Community document server is not supported for this instance, please setup and configure an external document server” appears, then you have to look for the exact error message in the log. To do this, you have to go to Logging in the admin area. If there is “OCA\DocumentServer\Document\DocumentConversionException: sh: ./x2t: cannot execute binary file: Exec format error” then your DiskStation has an ARM CPU and OnlyOffice does not run on it.

Next Steps

Now you can use Nextcloud directly in your browser, or you can download the client. The client works in a very similar way to Dropbox’s. You can synchronize your entire cloud with your computer or just individual folders. Synchronizing individual folders is also very helpful if you already have an existing folder structure for your data (images, videos, files, etc.) – e.g. on different drives – and you want to keep it. The client also enables the use of multiple Nextcloud instances. The client app for smartphones also offers the option of automatically uploading images. The data itself is not all downloaded to the smartphone until you call up individual files via the app.

Warnings and hints at the admin area

In the admin area under Overview you will most likely see some errors. You will find out how your Nextcloud is optimized and configured for actual use next time.

Would you like more detailed step-by-step instructions for your Synology NAS, with a lot more background information, tips and tricks? Then get my knowledge as a comprehensive practical manual. You won’t find more information in any book about Synology and everything in the quality I’m used to.

The new edition is completely reworked for DSM 7.

The book directly from the publisher (German only).

Related Posts

One thought on “Nextcloud installation on a Synology DiskStation with DSM 7.0

  1. Hi,
    Since upgrading to DSM7 the cron is not working. I am using
    DSM 7.1-42661 Update 1
    which comes with PHP80
    I followed all your steps but cron still reports that there is no memchache and stops.
    Any ideas?
    thanks

Leave a Reply

Your email address will not be published. Required fields are marked *