How to get Nextcloud to work on new installation of Truenas Scale 24.10

This is how I got Nextcloud to work on Truenas Scale 24:10. I tried to install the official app and that didn’t work. So instead I tried the YAML way and it worked for me. It will be a post that describes the process from the beginning so feel free to skip ahead. And if you find any errors or have some suggestions please ellaborate.

I’m using my myname_admin user account to set up these steps. I joined the groups builtin_administrators, builtin_users and truenas_admin when I set this user up. UID and GID is 3000. I also added a public key so that it is easy to login from my linux terminal with this command. You need to create home folder for this to work.

ssh -i '/path/to/your/cert/yourname_id_ecdsa' myname_admin@192.168.10.2 (your ip)

If you haven’t already, create a pool and a dataset to hold your applications and make sure to chose apps as your dataset preset. Create a nextcloud dataset under apps or whatever you made. I have put mine under /ridgeback2/apps/nextcloud. Now log into any terminal and navigate to /pool/apps/nextcloud. Create the following subdirectories: config, db, redis-data, ssl, user-data

sudo mkdir /mnt/pool/apps/nextcloud/config (etc)

Change ownership on the folders you created to your UID and GID

sudo chown 3000:3000 /mnt/pool/apps/nextcloud/config (etc)

In this setup I’m using the default SSL certs on the server so they need to be copied over

cp /etc/certificates/truenas_default.crt /mnt/pool/apps/nextcloud/ssl/
cp /etc/certificates/truenas_default.key /mnt/pool/apps/nextcloud/ssl/

Change owner if you need to and set permissions

sudo chown 3000/3000 /mnt/pool/apps/nextcloud/ssl/truenas_default.crt
sudo chown 3000/3000 /mnt/pool/apps/nextcloud/ssl/truenas_default.key
chmod 644 /mnt/pool/apps/nextcloud/ssl/truenas_default.crt
chmod 600 /mnt/pool/apps/nextcloud/ssl/truenas_default.key

Now everything should be set up to install Nextcloud via YAML script. On your Truenas server go into Apps → Discover Apps → 3 horisontal dots and chose install via YAML. Give a name to this setup, I called it nextcloud for obvious reasons. Then copy and paste this YAML code, edit as needed:

services:
  nextcloud:
    image: lscr.io/linuxserver/nextcloud:latest
    container_name: nextcloud
    environment:
      - PUID=3000
      - PGID=3000
      - TZ=Europe/Stockholm #or your TZ
      - MYSQL_HOST=db
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_PASSWORD=yourpassword #avoid " in your pw if you can
      - REDIS_HOST=redis
      - REDIS_HOST_PASSWORD=yourpassword #avoid " in your pw if you can
    volumes:
      - /mnt/ridgeback2/apps/nextcloud/config:/config
      - /mnt/ridgeback2/apps/nextcloud/ssl:/config/ssl
      - /mnt/ridgeback2/apps/nextcloud/user-data:/data
    ports:
      - 3010:443 #choose any port you like, I went with 3010
    depends_on:
      - db
      - redis
    restart: unless-stopped

  db:
    image: mariadb:latest
    container_name: nextcloud_db
    environment:
      - MYSQL_ROOT_PASSWORD=yourpassword #avoid " in your pw if you can
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_PASSWORD=yourpassword #avoid " in your pw if you can
    volumes:
      - /mnt/ridgeback2/apps/nextcloud/db:/var/lib/mysql
    restart: unless-stopped

  redis:
    image: redis:alpine
    container_name: nextcloud_redis
    command: ["redis-server", " --requirepass", "yourpassword"]
    volumes:
      - /mnt/ridgeback2/apps/nextcloud/redis-data:/data
    restart: unless-stopped

Save and watch the app deploy. The installation of nextcloud will change users on some folders under ./nextcloud. For example, the db folder is now owned by netdata:docker. Now you should be able to log into your Nextcloud running on Truenas Scale 24:10. I have not been able to make Collabora to work yet so if you have any ideas, please let me know. Here is some additional code you need:

list docker containers

sudo docker ps

move into container shell

sudo docker exec -it nextcloud (or id number) /bin/bash

in docker shell check the users you have

cat /etc/passwd

In my case, the docker container have created user abc with UID and GID 3000 which is the same UID and GID that we specified in the YAML file

Now find your occ path

find / -name occ

Confirm ownership of your path to use. This is where I found mine. The occ folder in this install is not where you would normally find it.

ls -al /app/www/public/occ

As you can see it is owned by user abc

-rwxr-xr-x 1 abc abc 308 Nov  4 09:17 /app/www/public/occ

Now we can use this path for maintenance tasks:

Turn on and off maintenance mode

sudo -u abc php /app/www/public/occ maintenance:mode --on
sudo -u abc php /app/www/public/occ maintenance:mode --off

Update and clean up cache

sudo -u abc php /app/www/public/occ files:scan --all 
sudo -u abc php /app/www/public/occ files:cleanup

Convert database from SQLite to MariaDB. As of now this can not be done yet, 2024-11-04

sudo -u abc php /app/www/public/occ db:convert-type --password='yourpassword' --all-apps mysql nextcloud localhost nextcloud

There is still some tinkering to do but at least for now I have a working Nextcloud install. One can also wait until 12 December for the next update and hope that Nextcloud will be fixed. I am not that patient though. Cheers!

Many thanks for this. I’m building a new server and perhaps foolishly went with 24.10. This is my 2nd Nextcloud build so not a lot of experience with Nextcloud.

Using your instructions everything installed and I see the 3 docker containers running. However, when I go to the Web logon to Nextcloud I get the “Install” screen that wants to set up a database. Trying various credentials and database configurations, at best, I get “Cannot create or write into the data directory” for the data folder I specify and it tells me to create an admin account. Do you know what combination of login, password, data folder, database credentials I need here?

Happy it was of any help setting up Nextcloud! I think your problem has to do with permissions. If you do

$ id youruser

in shell on your TrueNAS, is it the same UID and GID that you set up in your yaml file? And are you member of 544 (builtin_administrators), 545 (builtin_users) to? No need to be a member of truenas_admin group, that was a mistake by me in the description. Also you need to make sure that all the folders you made are owned by your admin account, the account you use for this setup.

I didn’t have any of your problems when I started my Nextcloud server.

But now when I come to think of it, my install defaulted to SQLite, I haven’t converted to MariaDB yet. I don’t know if this is the case for you?

I created a new user for Nextcloud and used it in the YAML and as owner of all the folders. It wasn’t a member of 544 but adding it and redeploying makes no difference.

I’m a bit confused when you say you used SQLite since your YAML references “mage: mariadb:latest” ?

When I run:

sudo -u abc php /app/www/public/occ db:convert-type --password=‘yourpassword’ --all-apps mysql nextcloud localhost nextcloud

I get:

This command is temporarily disabled (until the next maintenance release).

If I remember correctly you can’t use this command at the moment and that Nextcloud use SQLite in first install.

But have you tried to install the official Nextcloud container after updating TrueNAS to the latest version?

I tried the official Nextcloud container but couldn’t get it to work, while trying to find docs for 24.10 I came across your post… Like you, I cannot get the mysql conversion to run. However, your post made me realize that I was using the user name as seen by Truenas, and not the username inside the container, on the initial login. Switching to abc let me get Nextcloud up and running with Sqlite so it’s now running but I’m hesitant to do much with it until we know that mariadb can be made to work.

This all still leaves me wondering why you have the reference to “mariadb” in your YAML script, since it appears nextcloud is ignoring it?