nextcloud plugin on FreeNAS 11.2-rc1

ukos

Dabbler
Joined
Jul 22, 2018
Messages
12
The nextcloud plugin is available again in the plugins section. I wanted to share my experience when installing it here.
System: FreeNAS-11.2-RC1 (Build Date: Oct 17, 2018 23:38)

Screenshot from 2018-11-15 21-14-57.png


After hitting the install Button next to the plugin, the jail is created. MySQL database admin user dbadmin and password are printed out in the popup window. The default hostname is nextcloud and the nextcloud setup page becomes available on http://nextcloud in your local network.

Unfortunately it is not installing the nextcloud database and user automatically. So we need to do this via command line and input those values on the web frontend. This is definitely better done in the script from @danb35 or in the nextcloud docker-compose container setup.

To do this via command line, enter mysql prompt by executing
Code:
root@nextcloud:/ # mysql -udbadmin -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.42 Source distribution

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>


There is no nextcloud database installed. Check this by entering
Code:
mysql> show databases
	-> ;
+--------------------+
| Database		   |
+--------------------+
| information_schema |
| mysql			  |
| performance_schema |
| test			   |
+--------------------+
4 rows in set (0.00 sec)


To add the database, user and password, use the following commands:
Code:
CREATE DATABASE nextcloud;
CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY 'thisisyourpassword';
GRANT USAGE on nextcloud.* to 'nextcloud'@'localhost';
GRANT ALL PRIVILEGES on nextcloud.* to 'nextcloud'@'localhost';


Write down your credentials and input them to the web configuration ui.

I also decided to add some mountpoints for the jail:

Screenshot from 2018-11-15 21-24-15.png


This lets me keep data and config outside of the jail. The backup folder stores current mysql database backups.

I did not create mountpoint for the database, but in case anyone wants to keep the database data outside of the jail, the location of the files are the following:
  • config is at /usr/local/etc/mysql/conf.d and the
  • data is at /var/db/mysql
  • The my.cnf is at /usr/local/my.cnf, so the directory is probably /usr/local/my.cnf.d/

I have an installation, where I adjusted the blocksize of the underlying innodb to match with the zfs dataset but I will skip that here. I can not say, if it gives better performance. If anyone is interested, I could try.
You will also have to move the initial data and config content over to mount directories and delete the corresponding directories in /usr/local/www/nextcloud

After the installation succeeds, there are some errors in the admin section:

Screenshot from 2018-11-15 21-36-47.png


Code:
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.

Code:
[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


nextcloud related configuration is done in php-fpm.d/nextcloud.conf, so we need to copy the uncommented part over to this file.

Code:
[nextcloud]
...
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


after that, restart php and the error should disappear.

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


I tested if the webserver now sees the PATH variable by adding phptest.php to my webroot which only prints out the var:
Code:
<?php getenv("PATH");?>


Next Error was due for enabling the opcache in the php.ini.
The php.ini can be located by adding
Code:
phpinfo();
to the file above. It will point to /usr/local/etc/php.ini. Here are some commented lines which need to get activated according to the settings recommended by nextcloud. Also checkif opcache is enabled by viewing /usr/local/etc/php/ext-10-opcache.ini which should say
Code:
zend_extension=opcache.so
.

Next error is due to the nginx configuration:
Screenshot from 2018-11-15 22-13-50.png

Code:
The "Referrer-Policy" HTTP header is not set to "no-referrer", "no-referrer-when-downgrade", "strict-origin" or "strict-origin-when-cross-origin". This can leak referer information. See the W3C Recommendation ↗.


nginx configuration is located at /usr/local/etc/nginx/conf.d/nextcloud.conf and the recommended settings for nextcloud are here.
To target the above error, we basically would only care about adding
Code:
	   add_header Referrer-Policy no-referrer;


But(!) since the file in the jail highly differs from the recommended settings, has gzip deactivated and also seemed a bit old, I copied the currently recommended settings over and changed them to match
Code:
server_name _;
and
Code:
root /usr/local/www/nextcloud
.
Also the upstream redirection has to be changed to redirect to the correct unix socket:
Code:
upstream php-handler {
	server unix:/var/run/nextcloud-php-fpm.sock;
}

I am running a nginx reverse proxy which handles my TLS certificates so I removed the ssl related parts and only listen on port 80. Installing certbot would be next, if you want to do the certificate handling directly within this jail.

restart and test the nginx server using
Code:
root@nextcloud:/usr/local/etc/nginx/conf.d # /usr/local/etc/rc.d/nginx restart
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Stopping nginx.
Waiting for PIDS: 81103.
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Starting nginx.


I'm not sure if those changes get reverted if the plugin is updated, So I am thinking of adding additional mount points for my changes in /usr/local/etc/nginx/conf.d. Also I was wondering if anyone else ran into these issues with the plugin.
 

Attachments

  • Screenshot from 2018-11-15 22-12-32.png
    Screenshot from 2018-11-15 22-12-32.png
    10.6 KB · Views: 721

Lee Spangler

Dabbler
Joined
Sep 30, 2014
Messages
26
I am also getting these exact errors. I am not as experienced as you are, so I don't know how you are making the corrections.

What editor is available in the Jail? Heck, I dont really know how to make changes in the jail except to open a shell in the jail via the jail menu. Any newbie instruction is welcome.
 

samuel-emrys

Contributor
Joined
Dec 14, 2018
Messages
136
I am also getting these exact errors. I am not as experienced as you are, so I don't know how you are making the corrections.

What editor is available in the Jail? Heck, I don't really know how to make changes in the jail except to open a shell in the jail via the jail menu. Any newbie instruction is welcome.
It might be easier to use @danb35's script to install if you have no command line experience; it's better maintained than the plugins and support seems to be better. Alternatively, I wrote a very detailed manual installation guide targeted at beginners so it deals with a lot of the questions you'll have. It doesn't use the plugin, though.

To actually answer your question though, ee should be available in the jail by default, perhaps nano too.
 

ukos

Dabbler
Joined
Jul 22, 2018
Messages
12
Sorry for the techy post. I will not explain how to use the cli or recommend a specific editor (vi was missing above). That would be out of scope of what I intended. You should begin with something easier than installing nextcloud. It can be tedious.

I posted this here and actually hoped for a developer‘s response because the plugin has obviously not gotten a lot of love from freenas.

From a user‘s perspective, docker is the way to go but it is still marked experimental in FreeBSD (!).
I use the jails environment because of the low overhead compared to the current approach of freenas running docker in a VM.

The main advantage of freenas jails (in my opinion) is the custom mount point integration to the jails. Nextcloud needs a lot of them to work but you never know if the rest of your jail is intact, up-to-date and remains unchanged. The jail will always remain a temporary solution to me.

Considering easy installation, I can recommend Seafile. It has far better/faster file management using a real versioning system and Installation is extremely simple.
 

fahadshery

Contributor
Joined
Sep 29, 2017
Messages
179
@ukos could you please write some tutorial on how you're running nginx reverse proxy which handles your TLS certificates? This is something I have been thinking about doing recently.

thanks
 
Top