Files
Christian Galo 95e7f04cf5 docs: fix full text search setup order and elastic_host password
The live indexer must be stopped until fulltextsearch:index has created the index; otherwise Elasticsearch auto-creates it without the app mappings and the attachment pipeline, and file contents are never indexed. The elastic_host command now reads the secret inside the container instead of on the host. Also enable files_group_folders and document how to rebuild the index.
2026-11-25 02:35:21 +00:00

169 lines
5.6 KiB
Markdown

# Nextcloud
Wiki Cafe's configuration for a Nextcloud deployment. Originally slimmed down from an `abra` [recipe](https://git.coopcloud.tech/coop-cloud/nextcloud) by [Co-op Cloud](https://coopcloud.tech/).
This setup works in conjunction with [Caddy reverse proxy](https://git.coopcloud.tech/coop-cloud/caddy), handling TLS certificates via Let's Encrypt. This setup also includes labels for optional integration with [backupbot](https://git.coopcloud.tech/coop-cloud/backup-bot-two) for automated backups.
## Deploying the app with Docker Swarm
Create a new file `.env` in this directory with the following contents, adjusting as necessary:
```
STACK_NAME=nextcloud
DOMAIN=nextcloud.example.com
## Domain aliases
#EXTRA_DOMAINS=', `www.nextcloud.example.com`'
LETS_ENCRYPT_ENV=production
ADMIN_USER=admin
EXTRA_VOLUME=/dev/null:/tmp/.dummy
PHP_MEMORY_LIMIT=1G
# fpm-tune, see: https://spot13.com/pmcalculator/
FPM_MAX_CHILDREN=128
FPM_START_SERVERS=32
FPM_MIN_SPARE_SERVERS=32
FPM_MAX_SPARE_SERVERS=64
DEFAULT_QUOTA="500 MB"
# X_FRAME_OPTIONS_ENABLED=1
# X_FRAME_OPTIONS_ALLOW_FROM=embedding-site.example.org
# SMTP Config
# See https://github.com/nextcloud/docker#auto-configuration-via-environment-variables for default values
SMTP_AUTHTYPE=LOGIN
SMTP_HOST=mail.example.com
SMTP_SECURE=tls
SMTP_NAME=mail@example.com
SMTP_PORT=587
MAIL_FROM_ADDRESS=cloud
MAIL_DOMAIN=example.com
# Database tuning variables
INNODB_BUFFER_POOL_SIZE=1G
MAX_DB_CONNECTIONS=256
```
Set the environment variables from the .env file during the shell session:
```
set -a && source .env && set +a
```
### Creating Secrets
Set the secrets. The usual way to create a secret is:
```
printf "SECRET_HERE" | docker secret create SECRET_NAME -
```
The required secrets are:
- `db_password`: The MariaDB database password for the `nextcloud` user.
- `admin_password`: The Nextcloud admin user's password.
- `smtp_password`: The SMTP password for sending emails.
- `elasticsearch_password`: The Elasticsearch password.
- `db_root_password`: The MariaDB root user password.
We can generate these secrets using `openssl rand -base64 32` or similar.
```
openssl rand -base64 32 | docker secret create db_password -
openssl rand -base64 32 | docker secret create admin_password -
openssl rand -base64 32 | docker secret create smtp_password -
openssl rand -base64 32 | docker secret create elasticsearch_password -
openssl rand -base64 32 | docker secret create db_root_password -
```
### Deploying the App
Deploy using the `-c` flag to specify one or multiple compose files.
```
docker stack deploy nextcloud --detach=true -c compose.yaml -c compose.mariadb.yaml -c compose.smtp.yaml -c compose.fulltextsearch.yaml
```
### Enabling Full Text Search
To enable full text search, we first set up some environment variables for running commands inside the app and database containers:
```
export NC_APP="docker exec -u www-data -it $(docker ps --filter name=${STACK_NAME}_app --format '{{.ID}}' | head -n 1)"
export NC_DB="docker exec -it $(docker ps --filter name=${STACK_NAME}_db --format '{{.ID}}' | head -n 1)"
```
Stop the live indexer until the index is built. If it runs first, Elasticsearch creates the index on its own, without the app's mappings and without the `attachment` pipeline, and file contents never become searchable:
```
docker service scale ${STACK_NAME}_searchindexer=0
```
Next, run the following commands to install and configure the necessary Nextcloud apps for full text search with Elasticsearch:
```
$NC_APP php /var/www/html/occ app:install fulltextsearch
$NC_APP php /var/www/html/occ app:install fulltextsearch_elasticsearch
$NC_APP php /var/www/html/occ app:install files_fulltextsearch
$NC_APP php /var/www/html/occ config:app:set fulltextsearch search_platform --value="OCA\\FullTextSearch_Elasticsearch\\Platform\\ElasticSearchPlatform"
$NC_APP sh -c 'php /var/www/html/occ config:app:set fulltextsearch_elasticsearch elastic_host --value="http://elastic:$(cat /run/secrets/elasticsearch_password)@elasticsearch:9200/"'
$NC_APP php /var/www/html/occ config:app:set fulltextsearch_elasticsearch elastic_index --value="nextcloud"
$NC_APP php /var/www/html/occ config:app:set files_fulltextsearch files_local --value="1"
$NC_APP php /var/www/html/occ config:app:set files_fulltextsearch files_group_folders --value=true --type=boolean
```
Without `files_group_folders`, files in group folders are indexed by name only.
Verify the setup by running:
```
$NC_APP php /var/www/html/occ config:list files_fulltextsearch
```
Then, check for connectivity with Elasticsearch:
```
$NC_APP php /var/www/html/occ fulltextsearch:test
```
Manually build the search index. This creates the index and the `attachment` pipeline, then indexes every file:
```
$NC_APP php /var/www/html/occ fulltextsearch:index
```
Then start the live indexer again:
```
docker service scale ${STACK_NAME}_searchindexer=1
```
If you get “Index is already running”, a killed indexer left its lock behind. Clear it with:
```
$NC_APP php /var/www/html/occ fulltextsearch:stop
```
### Rebuilding the Search Index
If search only finds file names and not file contents, check that the pipeline exists. This should print `200`:
```
$NC_APP sh -c 'curl -s -o /dev/null -w "%{http_code}\n" -u elastic:$(cat /run/secrets/elasticsearch_password) http://elasticsearch:9200/_ingest/pipeline/attachment'
```
If it prints `404`, rebuild the index. The reset asks twice; the second time, type `reset ALL ALL`:
```
docker service scale ${STACK_NAME}_searchindexer=0
$NC_APP php /var/www/html/occ fulltextsearch:stop
$NC_APP php /var/www/html/occ fulltextsearch:reset
$NC_APP php /var/www/html/occ fulltextsearch:index
docker service scale ${STACK_NAME}_searchindexer=1
```