Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update version to 22 and enhance README #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FROM nextcloud:18.0.12-apache
FROM nextcloud:22-apache
170 changes: 128 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,106 @@
# Nextcloud on Dokku
> This is a complete overhaul of the initial fork from @dionysio that has been tested, confirmed working and used in production for Nextcloud 18.
# Nextcloud 22 on Dokku

With recent versions of Nextcloud, it became super easy to run `nextcloud` under dokku:
With recent versions of Nextcloud, it became super easy to run it under
[Dokku](https://dokku.com/) using [Nextcloud Docker
image](https://hub.docker.com/_/nextcloud).

## Requirements

You'll need access a server where you have Dokku installed with
[dokku-postgres](https://github.com/dokku/dokku-postgres) and
[dokku-letsencrypt](https://github.com/dokku/dokku-letsencrypt) plugins
enabled.

## Installtion

Connect to your Dokku server and set the following environment variables with
the values for your deployment:

```sh
dokku postgres:create nextcloud
dokku apps:create nextcloud
dokku postgres:link nextcloud nextcloud
# Execute on SERVER

APP_NAME="nextcloud"
PG_SERVICE_NAME="pg_${APP_NAME}"
APP_DOMAIN="nextcloud.example.com"
ADMIN_EMAIL="[email protected]"
DATA_PATH="/var/lib/dokku/data/storage/${APP_NAME}"
```

Then, from your machine, after cloning this repo and adding `dokku` as a remote:
Now, execute the following commands:

```sh
git push dokku
# Execute on SERVER

dokku apps:create $APP_NAME
dokku postgres:create $PG_SERVICE_NAME
dokku postgres:link $PG_SERVICE_NAME $APP_NAME
```

Now back to your dokku server!
Then, from your machine, add a `dokku` remote pointing to your server/app and
do the first push:

```sh
dokku domains:add nextcloud <your domain>
dokku letsencrypt nextcloud
# Replace this path with where you want to store user files (can be a network disk).
mkdir -p /var/lib/dokku/data/storage/nextcloud/data
chown www-data:www-data /var/lib/dokku/data/storage/nextcloud/data
# Execute on CLIENT (env vars set on server are not available here, so replace
# <...> with the correct values)

# Replace this path with where you want to store Nextcloud config (can be a network disk, but this'll make serving webpages much slower)
mkdir -p /var/lib/dokku/data/storage/nextcloud/config
chown www-data:www-data /var/lib/dokku/data/storage/nextcloud/config
git clone <this-repo-url>
cd dokku-nextcloud
git remote add dokku dokku@<your-server>:<your-app-name>
git push dokku main
```

dokku storage:mount nextcloud /var/lib/dokku/data/storage/nextcloud/data:/var/www/html/data
dokku storage:mount nextcloud /var/lib/dokku/data/storage/nextcloud/config:/var/www/html/config
# required to create the mount files (we pushed earlier)
dokku ps:restart nextcloud
[comment]: <> (TODO: we may change to the docker image deployment instead of git repository)

```
You're nearly done! Visit `<your domain>` to finish configuration.
Now back to your dokku server to finish the configuration!

Set up an admin account.
Click on "Storage & database".
Leave the data folder unchanged (`/var/www/html/data`)
For the database, **select Postgres**; you'll find the database credentials by running `dokku config nextcloud` and looking for DATABASE_URL: it'll look like postgres://USER:PASSWORD@HOST:PORT/DBNAME, just fill-in the fields on the webpage.
```sh
# Execute on SERVER

For instance, with `postgres://postgres:ae9e02101f9977e1fabb19f09605e486@dokku-postgres-nextcloud:5432/nextcloud`:
dokku domains:add $APP_NAME $APP_DOMAIN
dokku config:set $APP_NAME DOKKU_LETSENCRYPT_EMAIL=$ADMIN_EMAIL
dokku letsencrypt:enable $APP_NAME

* Database user: postgres
* Database password: ae9e02101f9977e1fabb19f09605e486
* Database name: nextcloud
* Database host: dokku-postgres-nextcloud:5432
for directory in config custom_apps data; do
mkdir -p "$DATA_PATH/$directory"
chown www-data:www-data "$DATA_PATH/$directory"
dokku storage:mount $APP_NAME "$DATA_PATH/$directory:/var/www/html/$directory"
done

Click on finish setup.
dokku ps:restart $APP_NAME
```

You're nearly done! Now:
- Visit `<your domain>` to finish configuration.
- Set up an admin account.
- Click on "Storage & database".
- Leave the data folder unchanged (`/var/www/html/data`)
- For the database, **select Postgres**; you'll find the database credentials
by running `dokku config $PG_SERVICE_NAME` and looking for DATABASE_URL:
it'll look like `postgres://USER:PASSWORD@HOST:PORT/DBNAME`, just fill-in the
fields on the webpage. For instance, with
`postgres://postgres:ae9e02101f9977e1fabb19f09605e486@dokku-postgres-nextcloud:5432/nextcloud`:
- Database user: `postgres`
- Database password: `ae9e02101f9977e1fabb19f09605e486`
- Database name: `nextcloud`
- Database host: `dokku-postgres-nextcloud:5432`
- Click on **finish setup**.


## Tweaks
If you're planning to use desktop client, because you're running with Dokku as a reverse proxy, you'll need to change your config.php file under `/var/lib/dokku/data/storage/nextcloud/config` to add this:

### Cache

You can make pages load faster (and save some CPU cycles) by adding a cache
layer to Nextcloud. It can be done by running [Redis](https://redis.io/) via
[dokku-redis](https://github.com/dokku/dokku-redis).

[comment]: <> (TODO: add commands to install redis plugin, create a Redis instance, link to the app and configure it on Nextcloud)

### Upload size

If you're planning to use desktop client, because you're running with Dokku as
a reverse proxy, you'll need to change your `config.php` file under
`$CONFIG_PATH` to add this:

```
'overwriteprotocol' => 'https'
Expand All @@ -63,17 +111,55 @@ Make sure the value for `'overwrite.cli.url'` starts with https.
You'll also need to allow large uploads to your server:

```sh
mkdir /home/dokku/nextcloud/nginx.conf.d/
echo 'client_max_body_size 50000m;' > /home/dokku/nextcloud/nginx.conf.d/upload.conf
echo 'proxy_read_timeout 600s;' >> /home/dokku/nextcloud/nginx.conf.d/upload.conf
chown dokku:dokku /home/dokku/nextcloud/nginx.conf.d/upload.conf
mkdir /home/dokku/$APP_NAME/nginx.conf.d/
echo 'client_max_body_size 50000m;' > /home/dokku/$APP_NAME/nginx.conf.d/upload.conf
echo 'proxy_read_timeout 600s;' >> /home/dokku/$APP_NAME/nginx.conf.d/upload.conf
chown dokku:dokku /home/dokku/$APP_NAME/nginx.conf.d/upload.conf
service nginx reload
```

### Cron

For some tasks you'll need to install a crontab. For this to work, you must
create an `app.json` file inside this repository, commit it and push to dokku's
app repository on your server. Check [Dokku docs on how to configure a cron
job](https://dokku.com/docs/processes/scheduled-cron-tasks/#dokku-managed-cron).

[comment]: <> (TODO: add sample `app.json`)
[comment]: <> (TODO: may use <https://github.com/crisward/dokku-require> and provide a sample app.json)

### Executing `occ` command

```sh
# Execute on the SERVER

container_id=$(docker ps | grep dokku/${APP_NAME}:latest | awk '{print $1}')
docker exec -it --user www-data $container_id php occ ...
```

## Uninstalling

If you're unhappy with your setup, this'll remove everything *forever*:

```sh
dokku apps:destroy $APP_NAME
dokku postgres:destroy $APP_NAME
rm -rf "$DATA_PATH" "$CONFIG_PATH"
```
dokku apps:destroy nextcloud
dokku postgres:destroy nextcloud
rm -rf /var/lib/dokku/data/storage/nextcloud
```

### Possible problems

#### Invalid private key

If the users are getting the annoying message "Invalid private key for
encryption app", update your private key password in your personal settings to
recover access to your encrypted files", look at [this issue
comment](https://github.com/nextcloud/server/issues/8546#issuecomment-371795233).


#### Could not establish a connection

If the users are getting the message "Could not establish a connection with at
least one participant" during videoconferences, then a TURN server might be
needed for your scenario, check more details at [Nextcloud TURN
docs](https://nextcloud-talk.readthedocs.io/en/latest/TURN.html).