Skip to main content

Setup nextcloud for local usage

I personally use syncthing to sync my files across devices, and it is enough for me. My parents, however, only have one device and don’t have the technical knowledge to set up the service. So, I am setting up nextcloud on my LAN, hoping it’ll work for them.

This guides is written for my system, which runs Alpine Linux. If you are familiar with Linux, though, you should be able to apply for your system, except for systems that has its own service configuring system, such as NixOS or GNU Guix perhaps.

Install the necessary packages

I am already having postgresql and nginx running on my system, so I’ll use them here as opposed to MariaDB and Apache httpd as recommended in the official doc.

sudo apk add nextcloud nextcloud-pgsql nextcloud-initscript

Configure the stuff

Next, I edit the data directory (where files are stored) to my /data/ partition, since the storage is bigger on there. To do this, I edit the config file /etc/nextcloud/config.php:

$CONFIG = array (
  'datadirectory' => '/data/nextcloud/data',
  'logfile' => '/var/log/nextcloud/nextcloud.log',

(I later learned that this can be configured during account setup.)

I also set trusted_domains to include the LAN address of the server:

'trusted_domains' => 
array (
  0 => '',
  1 => '192.168.0.x:12345',
  2 => '192.168.1.x:12345',

I add a postgresql user for nextcloud:

CREATE USER ncloud WITH PASSWORD 'very strong password';

Now, I create a nginx config for the service:

server {
        listen 12345;
        root /usr/share/webapps/nextcloud;
        index index.php index.html;
        disable_symlinks off;

        location / {
                try_files $uri $uri/ /index.html;

        location ~ [^/]\.php(/|$) {
                fastcgi_split_path_info ^(.+?\.php)(/.*)$;
                if (!-f $document_root$fastcgi_script_name) {
                        return 404;
                fastcgi_pass unix:/run/nextcloud/fastcgi.sock;
                        fastcgi_index index.php;
                include fastcgi.conf;
        # Help pass nextcloud's configuration checks after install:
        # Per
        location ^~ /.well-known/carddav { return 301 /remote.php/dav/; }
        location ^~ /.well-known/caldav { return 301 /remote.php/dav/; }
        location ^~ /.well-known/webfinger { return 301 /index.php/.well-known/webfinger; }
        location ^~ /.well-known/nodeinfo { return 301 /index.php/.well-known/nodeinfo; }

        client_max_body_size 100m;

Initialize the server

After configuring the services, I runs nextcloud and restart nginx:

sudo rc-service nextcloud start
sudo rc-service nginx stop
sudo rc-service nginx start
sudo rc-update add nextcloud

Now, I head to http://localhost:12345 where the server is running. It prompts for admin account and DB credentials. Filling these out, and it will shows recommended apps to install. I don’t care about these though, I just need file sync, so I skip this and go to create accounts for me and my parents.

Cleaning up

Since the ncloud user now no longer needs to create another database, it’s good practice to remove that privilege therefrom:


Would you like to discuss this post? Email me!