From 42506902d421d4c19bff6a4059dfd94231a69df6 Mon Sep 17 00:00:00 2001 From: Ngô Ngọc Đức Huy Date: Wed, 24 Apr 2024 22:48:16 +0700 Subject: New post: Setting up Nextcloud --- content/book-reviews/xkcd-what-if.md | 22 ----- content/posts/2024-04-24-setup-nextcloud.md | 123 ++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 22 deletions(-) delete mode 100644 content/book-reviews/xkcd-what-if.md create mode 100644 content/posts/2024-04-24-setup-nextcloud.md diff --git a/content/book-reviews/xkcd-what-if.md b/content/book-reviews/xkcd-what-if.md deleted file mode 100644 index 17100c5..0000000 --- a/content/book-reviews/xkcd-what-if.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -categories: ["book review"] -title: "XKCD: What If?" -date: 2021-05-07T16:35:08+07:00 -tags: [book, review, science, hypothetical, xkcd, whatif] -draft: true -book: "XKCD: What If?" -authors: ["Randall Munroe"] -isbn: 9780544456860 -genres: - - science - - humor -lang: en -layout: books ---- - -## Summary -## Comments - -### What I like - -### What I don't like 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 + '/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; +``` -- cgit 1.4.1