How to install Nextcloud on TrueNAS CORE

There are two ways to install Nextcloud on TrueNAS, one is via the provided plugin and one is manually. I prefer the manual one, on which you have more control and updates would not break it. While the plugin version is easy to setup, it is also the most easy one to break with updates. In this article I am going to show how to create a pool/jail and install Nextcloud on TrueNAS CORE from ground up.

Without wasting your time and going to any details which no one want to read, let’s get started.

Create a pool

If you have already created a pool, skip this part.

Go to Pools and click on the Add button.

truenas-core-pools

Type the pool name. Check the checkbox against the available disk and move it to the Data VDevs. Remember this is without RAID. Select the 2nd drive for RAID if you have 2. Both drives for the RAID has to be the same size.

Click Create to complete the process.

truenas-core-create-a-pool

This pool is available now as dataset and can be attached to the jail or a jail can be created in it.

You have to set permissions on this dataset, go to users and create a user like www (default web user) and assign it to this pool/dataset. Read more here.

If in case you want to use a default pool for a jail, and then mount this newly created pool/dataset as data point for Nextcloud data. That is another way of doing it. For that, just click on the three dots menu and click Add dataset.

Change ownership of the mount point once inside the jail shell, chown -R www:www /mnt/nc-data.

Create a jail

If you have already created a jail, skip this part.

A dataset must be created first to use jails. Select a pool from the gear icon where you want to create a jail.

Click on the Add button. Enter jail name, select Basejail as type, select the Release (choose the latest).

If you want to have a static IP, enter the IP in IPv4 Address field, keep DHCP unchecked and keep the rest as is.

Set Auto Start checked.

truenas-core-craete-a-jail

Setup web server

Once the jail is created, click on the Shell for that jail and you will be dropped to the jail shell as root.

Let’s update and install Apache, MySQL and other basic packages.

pkg update
pkg upgrade

pkg install wget curl vim ffmpeg bzip2 zip unzip apache24 mysql80-server redis

Start the services and set them to auto start on boot.

service apache24 start
service mysql-server start
service redis start

sysrc apache24_enable=yes
sysrc mysql_enable=yes
sysrc redis_enable=yes

If you get the following warning:

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.0.35. set the 'ServerName' directive gollbally to supress this message.

Add this to httpd.conf at the end. If you don’t have static IP, just add 127.0.0.1.

vim /usr/local/etc/apache24/httpd.conf
ServerName 192.168.0.35

Also enable the following modules in httpd.conf.

ratelimit_module
expires_module
proxy_module
session_module
http2_module
dav_module
dav_fs_module
dav_lock_module
rewrite_module

Test and restart Apache.

apachectl configtest
service apache24 restart

Install PHP and all the required PHP packages.

pkg install php74 php74-mysqli mod_php74 php74-gmp php74-bcmath php74-gd php74-json php74-curl php74-mbstring php74-intl  php74-xml php74-zip php74-fileinfo php74-pecl-imagick php74-session php74-zlib php74-pdo php74-pdo_mysql php74-bz2 php74-ctype php74-dom php74-exif php74-filter php74-iconv php74-ldap php74-openssl php74-opcache php74-pecl-APCu php74-pecl-redis php74-posix php74-simplexml  php74-xmlreader php74-xmlwriter php74-xsl

After installation to make Apache load PHP files, create or add 001_mod-php.conf in modules.d dir.

vim /usr/local/etc/apache24/modules.d/001_mod-php.conf

Add the following in it and save.

<IfModule dir_module>
    DirectoryIndex index.php index.html
    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php
    </FilesMatch>
    <FilesMatch "\.phps$">
        SetHandler application/x-httpd-php-source
    </FilesMatch>
</IfModule>

Configure PHP ini file.

cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini
vim /usr/local/etc/php.ini

Change the values of the following in php.ini or uncomment them.

post_max_size = 999M
upload_max_filesize = 999M
memory_limit = 512M

opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.revalidate_freq=1
opcache.save_comments=1

Check configuration and restart Apache.

apachectl configtest
service apache24 restart

Let’s create a database nextcloud.

mysql -u root -p

create database nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'ncuser'@'localhost' IDENTIFIED WITH mysql_native_password BY 'PASSWORD';
GRANT ALL ON * . * TO 'ncuser'@'localhost';

flush privileges;
exit

MySQL configuration file is /usr/local/etc/mysql/my.cnf.

Download and install Nextcloud

cd /usr/local/www

wget https://download.nextcloud.com/server/releases/nextcloud-24.0.1.zip

unzip nextcloud-24.0.1.zip

chown -R www:www nextcloud

mkdir /var/log/nextcloud

Create a nextcloud.conf virtual host file.

vim /usr/local/etc/apache24/Includes/nextcloud.conf
<VirtualHost *:80>
	ServerName 192.168.0.35
	DocumentRoot /usr/local/www/nextcloud

	<Directory "/usr/local/www/nextcloud">
		AllowOverride All
		Options -Indexes +FollowSymLinks
		Require all granted
	</Directory>

	ErrorLog /var/log/nextcloud/error.log
	#CustomLog /var/log/nextcloud/requests.log combined
</VirtualHost>
apachectl configtest
service apache24 restart

Create a cronjob as www user.

crontab -e -u www

*/5 * * * * php -f /usr/local/www/nextcloud/cron.php

It’s time to install Nextcloud. Hit the IP in the browser and start the installation process.

Data folder could be your mount point(/mnt/nc-data) or just the path as shown if you are using the pool as is.

truenas-core-nextcloud-installation

Leave a Reply

Your email address will not be published.