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]

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


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.


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 zlib
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'

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.


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'

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.

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


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
mysql Add mySQL Database support
postgres Add support for the postgresql database
sqlite Add support for sqlite - embedded sql database
vhosts Add support for installing web-based applications into a virtual-hosting environment


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



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



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

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

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.


Install the daemon:

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


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


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


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.


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;


To finish the configuration, run:

user $php occ notify_push:setup