Installing NextCloud Plugin on Freenas 11.3-U1 and upgrading to the latest NextCloud Version

NextCloud on Freenas 11.3

Replace Google Drive, DropBox and the like by hosting your own data!

By Fahad Usman

What is a NextCloud?

You can share and collaborate on documents, send and receive email, manage your calendar and have video chats without data leaks!

In other words, you could ditch Google, Microsoft and DropBox etc. to host your files (being in control of your own data without being data mined etc.)

The good thing is that FreeNas 11.3 comes with a NextCloud Plugin but setting it up is a pain in the back side. 

After struggling with it for a while, I finally managed to install it with all the security checks passed!

“Nextcloud Files offers an on-premise Universal File Access and sync platform with powerful collaboration capabilities and desktop, mobile and web interfaces.”

In this guide, I will take you through step by step how to set it up. However, this will not be connected to the internet because you will need to get a domain as well as port forwarding/duckdns etc. to be able to talk to it remotely.

Step 1 – Create Dataset via Storage Pool:

Create a new dataset in your existing pool within FreeNas. I like to have my data outside the jail. Edit permissions and assign the “USER” as “www” because that’s what NextCloud (NX hereafter) uses.

 

Step 2 – Install Plugin:

Install the Plugin via Plugins menu. Have DHCP option ticked. Once the installation is over, copy the notes into notepad/text editor for reference because it will contain your database and NX login usernames and passwords

 

1

Step 3 – Mount Storage:

You need to first Stop the Plugin. Then mount the internal dataset you just created to: /usr/local/www/nextcloud/data/nextclouddata

nextcl-2

Step 4 – Enable HTTPS:

You will need to create self signed SSL certificate and the private key first. For this, you will have to login via ssh into the FreeNas. Then type: jls to list the running jails on your FreeNas Box. Note the number that corresponds to nextcloud and then enter: jexec jail# tcsh.

This will change the prompt to nextcloud. This means that you’re inside the nextcloud jail, ready to make changes specifically to nextcloud.

Goto the Location: /usr/local/etc/ssl 

type the following to create the certificate in the jail terminal:

openssl req -x509 -nodes -days 3650 -newkey rsa:4096 -keyout nextcloud.key -out nextcloud.crt

This will create two files. Certificate and the private key.
You will have to reference these in the nextcloud.conf file.

To locate nextcloud.conf is just type:

find / -name nextcloud.conf

this will search for the file from the root directory.

mine was located at: /usr/local/etc/nginx/conf.d/nextcloud.conf 

Add the following inside server{:

server {

  listen 443 ssl;

  server_name _;

  ssl_certificate /usr/local/etc/ssl/nextcloud.crt;

  ssl_certificate_key /usr/local/etc/ssl/nextcloud.key;

  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

  ssl_session_cache    shared:SSL:1m;

  ssl_session_timeout  5m;

  ssl_ciphers  HIGH:!aNULL:!MD5;

ssl_prefer_server_ciphers on;

Restart nginx by: service nginx stop and then service nginx start

Goto your ip but this time with https://ip and it will give you a browser warning. Just add the certificate in your browser and it will then load.

Step 5 –  Enable MySql 4-byte support 

This was tricky. First here is the help page from the nextcloud site: https://docs.nextcloud.com/server/15/admin_manual/configuration_database/mysql_4byte_support.html

First you need to find where my.cnf file is. 

find / -name my.cnf

Mine was at: /usr/local/my.cnf. 

Now add the following at the end of this file and save:

innodb_large_prefix=true
innodb_file_format=barracuda
innodb_file_per_table=1 

Now login to mysql by: mysql -u yourusername -p and enter the dbpassword.
You can find out your login details by: cat /root/PLUGIN_INFO.

Now execute:

 

ALTER DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

Now find where you config.php file is.

mine was located at: /usr/local/www/nextcloud/config/config.php

Add the following at the end of the file just before the closing bracket “)” 

 

'mysql.utf8mb4' => 'true',

Restart nginx by: service nginx stop and then service nginx start

Restart mysql:  servic mysql-server restart and log back in to nextcloud and check under the settings to see if the warning is gone

 

Step 6 –  Fix php-fpm issue

This is the last step. Here is the error in the admin setting session of Nextcloud:

PHP does not seem to be setup properly to query system environment variables. The test with getenv(“PATH”) only returns an empty response. Please check the installation documentation  for PHP configuration notes and the PHP configuration of your server, especially when using php-fpm.

There seems to be some misconfiguration in the jail: The file /usr/local/etc/php-fpm.conf has a section that tries to fix the error, but the introduced changes there only apply to the generic www section.
Here is how the /php-fpm.conf 
Looks like:

[www]
...
;env[HOSTNAME] = $HOSTNAME
;env[PATH] = /usr/local/bin:/usr/bin:/bin
;env[TMP] = /tmp
;env[TMPDIR] = /tmp
;env[TEMP] = /tmp
env[HOSTNAME] = $HOSTNAME
env[PATH] = /bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

Just remove the ";" before these env and save the file. 

Nextcloud related configuration is in /usr/local/etc/php-fpm.d/nextcloud.conf file, so just paste this at the end of this file:

env[HOSTNAME] = $HOSTNAME
env[PATH] = /bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp 

and save the file. 

Restart php, mysql, nginx and the error should be gone:

/usr/local/etc/rc.d/php-fpm restart 

That’s it! Enjoy your own private cloud 🙂

Step 7 –  Upgrading to the latest version

You can easily upgrade to the latest NextCloud Version by going to the Settings menu and clicking the upgrade.

After Upgrade has been completed and you could log back in, checking setting again will give you an error of:

BigInt (64bit) identifiers

You could easily mitigate this error by ssh into your FreeNas NextCloud Jail and running these 3 commands:

su -m www -c 'php /usr/local/www/nextcloud/occ maintenance:mode --on'
su -m www -c 'php /usr/local/www/nextcloud/occ db:convert-filecache-bigint'
The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see http://php.net/manual/en/book.pcntl.php
Nextcloud is in maintenance mode - no apps have been loaded
Following columns will be updated:
* mounts.storage_id
* mounts.root_id
* mounts.mount_id
This can take up to hours, depending on the number of files in your instance!
Continue with the conversion (y/n)? [n] y
su -m www -c 'php /usr/local/www/nextcloud/occ maintenance:mode --off'

That’s it!

You could read more about this error here.

That’s it! Enjoy your own private cloud 🙂

Leave a Reply

Close Menu