diff options
author | Ngô Ngọc Đức Huy <huyngo@disroot.org> | 2024-04-24 22:48:16 +0700 |
---|---|---|
committer | Ngô Ngọc Đức Huy <huyngo@disroot.org> | 2024-04-24 22:48:16 +0700 |
commit | 42506902d421d4c19bff6a4059dfd94231a69df6 (patch) | |
tree | 9b084ad7f07e4f0c3d777eeaed46330d9ddcf775 /content/posts | |
parent | 11a7b9b66ce34258a895d2d875fe1e7c0a278b9c (diff) | |
download | blog-42506902d421d4c19bff6a4059dfd94231a69df6.tar.gz |
New post: Setting up Nextcloud
Diffstat (limited to 'content/posts')
-rw-r--r-- | content/posts/2024-04-24-setup-nextcloud.md | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/content/posts/2024-04-24-setup-nextcloud.md b/content/posts/2024-04-24-setup-nextcloud.md new file mode 100644 index 0000000..6851d3e --- /dev/null +++ b/content/posts/2024-04-24-setup-nextcloud.md @@ -0,0 +1,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; +``` |