Synology offers its own cloud solution, Synology Drive, but it is 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.
Update March 2021: Nextcloud 21 fix for database issues during the installation, Infos regarding DSM 7 Beta
Update December 2020: PHP 7.4 now also has the zip module.
Update September 2020: imagick is now supported with the lastes Web Station and PHP 7.3, PHP 7.4 doesn’t work at the moment.
DSM 7
This article is outdated and covers DSM 6.2, for the DSM 7 version see here.
Preperation
Hint
Always types commands for the command line yourself, do not copy them from the post. Double and single quotation marks are formatted differently in the text than in the command line. If you copy the characters, you adopt the wrong formatting, the characters are not recognized and the commands do not work.
Also creates scripts directly via the command line (with vi). If you create scripts with an editor on your computer and upload them to your DiskStation, they may contain control characters that prevent execution.
PHP 7.4
Synology updated their PHP 7.4 package and added the support for zip module. The new version is already available on Synology’s home page and should be soon also available via update in the Package Center. Now Nextcloud can be finally updated to use PHP 7.4.
Before we can start, check whether the Web Station is running or installed, if you haven’t already.
Important: If you use 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.
Install following packages via Package Center:
- PHP (7.4 or higher)
- phpMyAdmin (still needs PHP 5.6)
- Apache (2.4)
- MariaDB 10
Open MariaDB 10 and tick “Activate TCP / IP connection”.
Shared folder
Create a new shared folder that will be used to store your files. Nextcloud saves the files 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 Nextcloud later on. 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. Those changes should only be done 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 Folders, if you create the folder via PuTTY, DSM does not recognize it and you e.g. can’t back it up via Hyper Backup.
To allow PHP to also access the shared folder, the path must be entered in open_basedir. Open the Web Station > PHP settings. Insert the path at the end of the “custom open_basedir” field. The colon (:) separates the individual paths. For details see section “PHP profile”.
Activate the SSH service under Control Panel > Terminal & SNMP. Open PuTTY and connect to the DS. Log in as an administrator. To run the commands as root, type sudo –i
and press Enter. Enter your administrator password again. Enter the following 2 commands:
chown http:http /volume1/nextcloudData chmod -R 777 /volume1/nextcloudData
Otherwise, Nextcloud cannot access the folder. If you have activated the option to hide the folder from unauthorized users, you should no longer see the folder in the File Station.
PHP profile
Open the Web Station and create a new profile under PHP settings.
- Enter a name and a description.
- Select “PHP 7.4” (or higher).
- Check “Enable PHP Cache”.
- Activate “Customize PHP open_basedir” and enter
/tmp:/var/services/tmp:/var/services/web
. Now add the path to the shared folder that you created earlier (don’t forget the colon). The whole thing could look like this:/tmp:/var/services/tmp:/var/services/web:/volume1/nextcloudData
- Activate the following extensions: bcmath, bz2, curl, ftp, gd, gmp, iconv, intl, mysqli, openssl, pdo_mysql, posix, ssh2, zip, zlib
It is best to use a virtual host, this prevents some problems and you can configure Nextcloud better. You can read more about running Nextcloud as a virtual Host, in this article.
Server timeout
Next, you have to increase the web server timeout, the installation process can take some time, especially on weaker DiskStations. This can lead to a timeout, the installation is still getting finished in the background and you just have to reload the page, but the whole thing is a bit cumbersome. You don’t know when the installation is finished and if you refresh the page too early, there is a chance that the installation is broken.
- Open the file
/etc/nginx/proxy.conf
in PuTTY (as root). - Add the entry
proxy_read_timeout 600;
at the end. - Save and close the file.
- Test the configuration with
nginx -t
. If you have installed a package that sets the timeout itself (e.g. WordPress), the test fails. In the error message you can see in which file the timeout was set. Open the file and delete the timeout entry there. If the value is higher than 600, adjust the value in/etc/nginx/proxy.conf
. Run the test again and fix any errors. - Restart the nginx with
synoservice -restart nginx
. - Create the file
/usr/local/etc/apache24/sites-enabled/apache_nextcloud.conf
with PuTTy and inserts the following lines:
ProxyTimeout 600 Timeout 600 <IfModule reqtimeout_module> RequestReadTimeout body=0 </IfModule>
- Save and close the file and restart Apache, which is cumbersome by starting and stopping the Web Station, restarting DiskStation or you create a scheduled task: Task Scheduler > Service > Start / Stop task for Apache. Deactivate the tasks and manually executes the stop task first, wait a moment and then execute the start task.
That was a lot of steps already, but the preparation is complete and the installation can begin.
Installation
Download the latest version of Nextcloud as a .zip or .tar here. Upload the zip file to your DiskStaion and extract it into the /web
folder.
Tip
To increase security, you can rename the Nextcloud folder. This prevents it from being found by crawlers searching web roots for standard labels.
Change the permissions 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, type sudo –i
and press Enter. Enter your administrator password again. Now run the script with sh /volume1/PathToScript/Install_Permissions.sh
. Instead of the script, you can also enter line by line in the shell, but that’s tedious, and you have to change the permissions for an update again.
Note
The permissions are only intended for installation, for safe operation they should be kept as strict as possible. Read here how to adjust the permissions after the installation.
Problematic SQL statement (Nextcloud 18 and 19)
Nextcloud’s setup automatically creates a database including tables and its own user. The current version of MariaDB 10 from Synology has problems with the syntax in the installation file. So that the installation can be carried out correctly, the problematic lines must be adjusted:
- Open the file
/volumeX/web/Nextcloud/lib/private/Setup/MySQL.php
(with PuTTY). - Scroll down almost to the end of the file and look for those 2 lines:
$query = “CREATE USER ‘$name’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘$password’”; $query = “CREATE USER ‘$name’@’%’ IDENTIFIED WITH mysql_native_password BY ‘$password’”;
- Remove “WITH mysql_native_password”, so that the result looks like this:
$query = “CREATE USER ‘$name’@‘localhost’ IDENTIFIED BY ‘$password’”; $query = “CREATE USER ‘$name’@’%’ IDENTIFIED BY ‘$password’”;
- Save and close the file.
Attention
After the installation you have to undo the change, otherwise you will get an error message from Nextcloud’s file integrity check.
Problematic Database script (Nextcloud 21)
The Nextcloud setup automatically creates a database including tables and its own user. Nextcloud 21 also uses a syntax that causes problems with Synology’s version of MariaDB 10. So that the installation can be carried out correctly, the problematic lines must be adjusted:
- Open (with PuTTY) the file /volumeX/web/Nextcloud/lib/private/Setup/MySQL.php
- Scrollt almost to the end an look for following line:
$this->dbPassword = $this->random->generate(30, ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER);
- Remove “
, ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER
“, so it looks like this:
$this->dbPassword = $this->random->generate(30);
- Save and close the file.
Attention
After the installation you have to undo the change, otherwise you will get an error message from Nextcloud’s file integrity check.
Run the installation assistant
Open Nextcloud in the browser. Make sure to use the host address, you have configured the virtual host with (e.g. cloud.mydomain.com). If you have not configured a virtual host, use the IP, the name of the DiskStation 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 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 you e.g. want to reach the cloud later via your own domain or DynDNS, but use the local name or the local IP of the DiskStation during installation.
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 Location” /volumeX/web/nextcloud/data
is entered by default, enter the path to the shared folder that you created earlier.
In the section “Database” you have to enter the root user of MariaDB and the password. Alternatively, every user who has the right to create databases can be used. The user is only used for installation. A separate user is created that Nextcloud uses for operation. The user you enter here, is stored nowhere. Assign a name for the database.
Attention
The default database server is localhost, for MariaDB 10 you have to replace localhost with 127.0.0.1:3307.
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 later. That makes sense, especially since you can only use Talk and OnlyOffice on DiskStations with an Intel CPU. The apps are very large, if you don’t need them, save space and time and install e.g. Calendar and Contacts afterwards.
Click on the button Finish setup to run the installation. After a few moments everything should be done and you should see the web interface.
Prevent issues
Before the setup, we adapted the installation script for the database. Nextcloud checks all files belonging to the Nextcloud installation for changes and issues a warning message. That could also interfere with the update. 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 permissions again.
Activate OnlyOffice
Nextcloud calls it “integrated”, but even if you installed OnlyOffice during the setup, nothing works yet. The integration is still a big thing, as you had to previously use docker to run OnlyOffice and Docker on DiskStations is a horrible configuration nightmare (as the Synology version of Docker does not always work as someone expects Docker to work). With the integrated version of OnlyOffice, Docker is not needed anymore, but it still requires x86-CPUs to run, so if your DiskStation has an ARM-CPU you can skip this part.
Not officially documented, another app must be installed. Open the App store by clicking on you user icon an choosing + Apps.
If you haven’t installed the recommended apps: Search for the ONLYOFFIC app. You can find it in the Office & Text section. Download the app and activate it. Then look for the Community Document Server app, also under Office & Text. Download the app and activate it. You have to carry out this step even if you have installed the recommended apps.
Installation issue
Apparently there are problems with timeouts (not the one we addressed earlier) during the installation again. Instead of installing the app via the web interface, you may need to connect via PuTTY, switch to your Nextcloud installation folder and run sudo -u http php73 -d memory_limit=512M occ app:install documentserver_community
. It is important to increase the memory limit. The process then takes some time, the app is quite large.
Synology causing issues again. A file is missing, but with a few extra steps this can be fixed:
- Download libstdc ++ 6 for Debian here.
- Unpack the following file:
data.tar\.\usr\lib\x86_64-linux-gnu\libstdc++.so.6.0.25
- Renames the file to
libstdc++.so.6
.
Attention
There is already a file with this name in the archive, but this is a symbolic link and not a file, unpacking fails, hence the detour via the real file and renaming.
- Upload the file to your DiskStation.
- Copy the file with PuTTY:
cp <PathToFile> /volume1/web/nextcloud/apps/documentserver_community/3rdparty/onlyoffice/documentserver/server/FileConverter/bin
- Adjust the permissions and owner of the file. The owner must be
http:http
. Use the commands given under “Installation”.
Updating Community Document Server
If you update the app “Community Document Server” you have to copy over the libstdc++ file again as it gets deleted during the update.
Now go to the admin area: Upper right menu bar, click on the user icon and choose 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 for document processing”. If you use https – which is highly recommended – the URL must match the Host, the SSL certificate is issued for.
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 in the log for the exact error message. 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. There are currently many other errors.
Further steps
Now you can use Nextcloud directly in your browser, or you can download the client. The client works very much like Dropbox. 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 them. The client also enables the use of multiple Nextcloud instances. The client app for smartphones also offers the option of automatically uploading photos. The data itself is not all downloaded to the smartphone until you call up individual files via the app.
In the admin area under Overview you will most likely see some errors. How you can eliminate this and how to optimize Nextcloud, you can read in the next article in the series. You can also find other useful articles about Nextcloud and Synology here.
Thanks for the tutorial, now the Nextcloud installation finally worked under the DSM 7.
I have been looking for a solution for ages, why the installation only works with sqllite and not with mariadb.
With the changes under the following points
– Problematic SQL statement (Nextcloud 18 and 19)
– Problematic Database script (Nextcloud 21)
it finally worked.
Thanks a lot
Hi there
I got this error
OCA\DocumentServer\Document\DocumentConversionException: ./x2t: error while loading shared libraries: /volume1/web/nextcloud/apps/documentserver_community/3rdparty/onlyoffice/documentserver/server/FileConverter/bin/libstdc++.so.6: invalid ELF header
Hi,
Have you downloaded the correct libstdc ++ 6, renamed the file and copied it to the NC folder?
Cheers,
Andreas
Thx for this tutorial, here are some typos or missing parts I found (at least on latest the dsm 6.2.3) it should be:
zlib is also needed at least for nextcloud-20.0.4.zip
Fehler PHP-Modul zlib nicht installiert.
————————————————–
-> Activate the following extensions: bcmath, bz2, curl, ftp, gd, gmp, iconv, intl, mysqli, openssl, pdo_mysql, posix, ssh2, zip
those should be proxy.conf at least for me:
————————————————————-
->Open the file /etc/nginx/proxy/conf in PuTTY (as root).
->If the value is higher than 600, adjust the value in /etc/nginx/proxy/conf. Run the test again and fix any errors.
/web/ is missing – i think – it should be /volumeX/web/Nextcloud/lib/private/Setup/MySQL.php:
—————————————————————————————————————————————-
-> Open the file /volumeX/Nextcloud/lib/private/Setup/MySQL.php (with PuTTY).
Thx for the hint, I forgot to update the english version last time.
Hi Andreas,
Thank you for all your work about Synology/nextcloud configuration, not as easy… I am looking for a solution to get rid of timeout troubles when installing Onlyoffice or others. I have read on several sites that I shloud execute the command sudo -u http php73 -d memory_limit=512M occ app:install documentserver_community to avoid web timeout but actually I am on mac and I am using vim.
Could you please help me figure out the equivalent of this command for vim ?
Regards,
Johan
I made progress with my understanding of small networks, timeouts issues and usage of vim etc… thanx to your tutos , no more timeouts and Only Office is finally working with Nextcloud 20 on my NAS. I also noticed Collabora is taking a lot of CPU. Since I deactivated it, nextcloud is working a lot better… That’s a shame as I really liked to try it also. Do you have any experience with it ?
Thanx a lot agin and hope your Nextcloud/Synology guide will be available in French or English in the months to come… !
Great tutorial an following it now to install NextCloud on a DS718+ with 8Gb memory.
I came to the part ONLYOFFIC and must run this command in putty. I am in Nextcloud folder an run
sudo -u http php73 -d memory_limit = 512M app: install documentserver_community
But getting an error: Could not open input file: =
So change it to:
sudo -u http php73 -d memory_limit = 512M app: install documentserver_community
Removed the spaces for =
Now getting:
Could not open input file: app:
Could not find any info about the command so hoping you can share the right command line. I think it is a format thing.
Hi,
Thx for pointing that out, the spaces were added by text formatting. Also the “occ” command was missing, it must be:
sudo -u http php73 -d memory_limit=512M occ app:install documentserver_community
Regards
Andy
Tnx Andy,
Will try this soon and again tnx for the great tutorial.