NextCloud - uthomelabs/guides GitHub Wiki
Overview
Some of the most-used hosted software platforms include productivity suites (file hosting/syncing, office/document editing software, photo management, etc.). Whether it be Google Docs/Drive/Photos, Microsoft Office/OneDrive/Photos, etc. there are a lot of options out there. Businesses and consumers alike use these platforms every day... but what if you don't really trust Google or Microsoft to handle your personal data and documents? For those who like to self-host things NextCloud is probably the best open-source self-hosted platform that bundles all of these features.
Prerequisites
For the purposes of this guide we'll be setting NextCloud up using Docker so you will at minimum need:
- A computer/server, virtual machine, or other system to bring up the stack
- Docker with the Compose plugin
NextCloud has a couple options for its database backend. The simple/default way is to just use SQLite, but for the sake of showing something a little more robust we'll go through setting it up with a separate database using MariaDB.
Running with Compose
Of all the manageable ways to set up NextCloud docker compose might be the best way to get started here. Go ahead and set up a directory to work from and copy the compose file below:
# Make a place to work from
mkdir lab-guides && cd lab-guides
# Make the needed paths
mkdir -p nextcloud/{dbdata,data,secrets}
# Generate some passwords and secure them
pwgen -snc 30 1 > nextcloud/secrets/db_root.secret
pwgen -snc 30 1 > nextcloud/secrets/db_nc.secret
pwgen -snc 30 1 > nextcloud/secrets/admin.secret
chmod 600 nextcloud/secrets/*
vim docker-compose.yml # or another editor if you prefer :D
Now go ahead and copy the compose file (or add the contents to an existing compose file):
docker-compose.yml
secrets:
nextcloud_db_root:
file: "./nextcloud/secrets/db_root.secret"
nextcloud_db_nc:
file: "./nextcloud/secrets/db_nc.secret"
nextcloud_admin:
file: "./nextcloud/secrets/admin.secret"
services:
nextcloud-mariadb:
image: "mariadb:10.10"
container_name: "nextcloud-mariadb"
secrets:
- "nextcloud_db_root"
- "nextcloud_db_nc"
command: "--transaction-isolation=READ-COMMITTED --binlog-format=ROW"
environment:
MARIADB_ROOT_PASSWORD_FILE: "/run/secrets/nextcloud_db_root"
MARIADB_DATABASE: "nextcloud"
MARIADB_USER: "nc"
MARIADB_PASSWORD_FILE: "/run/secrets/nextcloud_db_nc"
volumes:
- "${PWD}/nextcloud/dbdata:/var/lib/mysql"
restart: "unless-stopped"
nextcloud:
image: "nextcloud:apache"
container_name: "nextcloud"
secrets:
- "nextcloud_db_nc"
- "nextcloud_admin"
environment:
MYSQL_HOST: "nextcloud-mariadb"
MYSQL_DATABASE: "nextcloud"
MYSQL_USER: "nc"
MYSQL_PASSWORD_FILE: "/run/secrets/nextcloud_db_nc"
NEXTCLOUD_ADMIN_USER: "admin"
NEXTCLOUD_ADMIN_PASSWORD_FILE: "/run/secrets/nextcloud_admin"
volumes:
- "${PWD}/nextcloud/data:/var/www/html"
ports:
- "8080:80/tcp"
depends_on:
- "nextcloud-mariadb"
restart: "unless-stopped"
Now go ahead and bring up the services:
$ docker compose up -d
docker compose up -d
[+] Running 30/30
⠿ nextcloud Pulled 34.7s
⠿ 025c56f98b67 Pull complete 8.4s
⠿ db4ab4019a6f Pull complete 8.5s
⠿ 19c3d46c565a Pull complete 14.4s
⠿ 7d52c3b9728a Pull complete 14.7s
... snip ...
⠿ a6c355316dd8 Pull complete 21.6s
⠿ 1b84524cf1cb Pull complete 32.7s
⠿ dc6f0e9987bc Pull complete 32.8s
⠿ 4f331917b1fa Pull complete 33.9s
⠿ nextcloud-mariadb Pulled 27.6s
⠿ 6e3729cf69e0 Pull complete 17.9s
⠿ 0b2128efbd85 Pull complete 18.1s
⠿ 94c8eab958ce Pull complete 19.2s
⠿ 73cc9c81ae7f Pull complete 19.4s
⠿ 20bcac65cb84 Pull complete 19.5s
⠿ c4a9b64b12f6 Pull complete 26.3s
⠿ 890f8c45a000 Pull complete 26.6s
⠿ 97533be58132 Pull complete 26.7s
[+] Running 2/2
⠿ Container nextcloud-mariadb Started 2.8s
⠿ Container nextcloud Started 2.3s
It takes a little while to actually spin everything up so you might need to give it a few minutes. You can see the processes up and running like this:
$ docker compose ps
Name Command State Ports
--------------------------------------------------------------------------------------------------
nextcloud /entrypoint.sh apache2-for ... Up 0.0.0.0:8080->80/tcp
nextcloud-mariadb docker-entrypoint.sh --tra ... Up 3306/tcp
If you want to watch the logs for the nextcloud
container to see when it's ready you can do so by just running:
$ docker compose logs -f nextcloud
Attaching to nextcloud
nextcloud | Initializing nextcloud 25.0.2.3 ...
nextcloud | New nextcloud instance
nextcloud | Installing with MySQL database
nextcloud | Starting nextcloud installation
nextcloud | Nextcloud was successfully installed
nextcloud | Initializing finished
Accessing the service
Once everything is up and running you should be able to access it on the host:port
that it's running on. In the case of running it exactly as above on your own machine you would pull up http://localhost:8080 in your web browser. If all has gone well and the nextcloud
container is finished installing everything you should see a sign-on screen like this:
You can now copy that admin
user password you generated (try cat nextcloud/secrets/admin.secret
and copy that) and use those credentials to log into NextCloud and configure it how you like!
Note on non-localhost access
If you are accessing NextCloud via a proxy/domain or anything other than localhost
then you'll need to allow whatever IP/domain you're using to access it
Option A
You can get the currently configured hosts with:
docker exec --user www-data nextcloud php occ config:system:get trusted_domains
and you can add an entry with: (where $index is +1 the value returned in the previous command and $url is the host/IP/etc. you'd like to add)
docker exec --user www-data nextcloud php occ config:system:set trusted_domains $index --value=$url
Option B
Edit the NextCloud configuration file to "trust" the domain(s). Just edit the config.php
file for it:
vim nextcloud/data/config/config.php
and update the trusted_domains
array to include the IP/domain name you're using. The default looks like:
...
'trusted_domains' =>
array (
0 => 'localhost',
),
...
and you should add another array value or replace that one accordingly:
...
'trusted_domains' =>
array (
0 => 'localhost',
1 => 'nextcloud.mydomain.com',
2 => '10.10.10.25',
),
...
If you do this you may need to restart the container:
$ docker compose restart nextcloud