about summary refs log tree commit diff
path: root/content/posts/2024-04-24-setup-nextcloud.md
blob: 6851d3e42ed949f093e9c846283080353c7c30c6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
---
title: "Setup nextcloud for local usage"
date: 2024-04-24
lang: en
categories: [ blog, sysadmin ]
tags: [sysadmin, guide, nextcloud]
translationKey: "2024-04-24-setup-nextcloud"
---

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][nc-doc].

[nc-doc]: https://docs.nextcloud.com/server/latest/admin_manual/installation/system_requirements.html


```bash
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`:

```php
<?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:

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

I add a postgresql user for nextcloud:

```sql
CREATE USER ncloud WITH PASSWORD 'very strong password';
ALTER ROLE ncloud CREATEDB;
```

Now, I create a nginx config for the service:

```nginx
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 https://docs.nextcloud.com/server/22/admin_manual/issues/general_troubleshooting.html#service-discovery
        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:

```bash
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:

```sql
ALTER ROLE ncloud NOCREATEDB;
```