Nextcloud

From Gentoo Wiki
Jump to:navigation Jump to:search

Nextcloud is a free and open source cloud hub primarily intended for file synchronization and sharing. It features a rich ecosystem of different apps .

This installation document was written with Nextcloud 26 as a target and attempts to provide a fast installation on Gentoo systems.[1]

Note
This guide is about installing the web server components of Nextcloud. It contains no instructions on installing the (optional) desktop client.

Requirements

Nextcloud requires software components from the standard (L)AMP stack: a web server, a database, and PHP (php-fpm). Apache and Nginx are supported web servers.

PHP

Before (re-)emerging PHP in order to get supported modules, see upstream's list of supported PHP versions and associated modules[2] which are necessary for correct operation of Nextcloud.

Warning
These USE flags for dev-lang/php are required in order for Nextcloud to function correctly: ctype curl fileinfo filter gd iconv ssl posix session simplexml xmlreader xmlwriter zip zlib
Important
Please choose one of PostgreSQL, MySQL/MariaDB or sqlite (only lite installations only) databases to hold Nextcloud's data. This tutorial will use PostgreSQL (recommended) as the database, thus adding the postgres USE flag. MySQL would use mysql while sqlite would employ sqlite.

Verify one of three possible modules exist for PHP's database connector. In this instance, PostgreSQL will be the application's database, therefore in addition to Nextcloud, PHP will need the postgres USE flag:

user $php -m | grep -i 'pdo_pgsql'
pdo_pgsql

Generally recommended USE flags are bzip2 gmp bcmath exif intl sysvipc.

After installing or uninstalling any PHP modules, the web server, and/or php-fpm depending on the configuration, each service will need to be restarted to register the changes.

Caching

Recommended for enhanced server performance is to pair Nextcloud with memcached or others. This PHP module is a PHP Extension Community Library (PECL) extension and is installed separately from PHP itself:

root #emerge --ask dev-php/pecl-memcached

memcached package must also be installed:

root #emerge --ask net-misc/memcached

Verify the memcached module is available to PHP:

user $php -m | grep -i 'mem'
memcached

Signed SSL certificate (Let's Encrypt)

Let's Encrypt can be used to obtain free certificates which have been signed by a recognized signing authority.

root #certbot --apache --rsa-key-size 4096 --staple-ocsp --hsts

Simply choose a desired domain and request the certificate.

Note
For nginx, simply use this command instead:
root #certbot --nginx --rsa-key-size 4096 --staple-ocsp --hsts

Installation

Once PHP, Apache and (optionally) the caching service have been installed, simply set the USE flags for nextcloud and emerge the service.

USE flags

USE flags for www-apps/nextcloud Personal cloud that runs on your own server

+curl Add support for client-side URL transfer library
+imagemagick Enable optional support for the ImageMagick or GraphicsMagick image converter
+sqlite Add support for sqlite - embedded sql database
mysql Add mySQL Database support
postgres Add support for the postgresql database
vhosts Add support for installing web-based applications into a virtual-hosting environment

Emerge

root #emerge --ask www-apps/nextcloud

The following command is a recommendation for webapp-config:

root #webapp-config -h /nextcloud -d / -I 26.0.0

Configuration

Files

/var/www/nextcloud/htdocs - Contains the nextcloud files if the install was performed using the recommended method.

Service

Database

MySQL and MariaDB

MySQL or MariaDB databases are the recommended database engines.

To enable on Gentoo, set the mysql USE flag. It is recommended to disable sqlite and postgres when using a MySQL-based database implementation.

FILE /etc/portage/package.use/nextcloudEnable MySQL database support
www-apps/nextcloud mysql

Ask Portage to rebuild the world set:

root #emerge --ask --update --deep --newuse @world

Run the configuration step to create and set proper permissions on the database directories and assist setting the database root user's password (Note - this is for the MariaDB root user account, which is not the same as the operating system's root user account!):

root #emerge --ask --config dev-db/mariadb

Be sure to save the database root user's password in a secure enclave for safe keeping!

The MariaDB server can be enabled and started:

root #systemctl enable --now mariadb.service
Postgres

When running a Postgres databases, instantiate before running the service. This will create appropriate runtime directories, etc.

root #emerge --config dev-db/postgresql:16

OpenRC

On an OpenRC system Nextcloud does not have a specific service, but runs on services from the LAMP stack:

root #rc-update add postgresql-16 default
root #rc-update add apache2 default

systemd

root #systemctl enable --now postgresql-16
root #systemctl enable --now apache2

notify_push support

Normally, clients pull updates from the server periodically. With many clients it can create a significant load on your server. The Client Push application can help you to reduce it.

Emerge

Install the daemon:

root #emerge --ask www-apps/nextcloud-notify_push

Service

To start the daemon at boot, run the following commands:

OpenRC

root #rc-service nextcloud-notify_push start
root #rc-update add nextcloud-notify_push default

systemd

root #systemctl start nextcloud-notify_push.service
root #systemctl enable nextcloud-notify_push.service

Reverse proxy

The daemon should listen on the /push/ location of your Nextcloud installation.

Nginx

CODE
location ^~ /push/ {
    proxy_pass http://unix:/run/nextcloud-notify_push/notify_push.socket:/;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

Setup

To finish the configuration, run:

user $php occ notify_push:setup https://cloud.example.com/push

References