Nextcloud
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]
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.
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 zlibPlease 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 and pdo USE flags. MySQL would use mysql while sqlite would employ sqlite.Generally recommended USE flags are bzip2 gmp bcmath exif intl sysvipc.
You can emerge PHP with:
root #emerge --ask dev-lang/phpVerify one of three possible modules exist for PHP's database connector:
user $php -m | grep -i 'pdo_pgsql'pdo_pgsql
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-memcachedmemcached package must also be installed:
root #emerge --ask net-misc/memcachedVerify 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 --hstsSimply choose a desired domain and request the certificate.
For nginx, simply use this command instead:
root #certbot --nginx --rsa-key-size 4096 --staple-ocsp --hstsInstallation
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/nextcloudThe following command is a recommendation for webapp-config:
root #webapp-config -h /nextcloud -d / -I nextcloud 26.0.0Configuration
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.
/etc/portage/package.use/nextcloudEnable MySQL database supportwww-apps/nextcloud mysql
Ask Portage to rebuild the world set:
root #emerge --ask --update --deep --newuse @worldRun 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/mariadbBe 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.servicePostgres
When running a Postgres databases, instantiate before running the service. This will create appropriate runtime directories, etc.
root #emerge --config dev-db/postgresql:16OpenRC
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_pushService
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
location^~/push/{ proxy_passhttp://unix:/run/nextcloud-notify_push/notify_push.socket:/; proxy_http_version1.1; proxy_set_headerUpgrade$http_upgrade; proxy_set_headerConnection"Upgrade"; proxy_set_headerHost$host; proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for; }
Setup
To finish the configuration, run:
user $php occ notify_push:setup https://cloud.example.com/push