How to Install NextCloud on OpenMediVault 5 with Remote Access and SSL

How to Install NextCloud on OpenMediVault 5 with Remote Access and SSL

In diy, OpenMediaVault, Tutorials, Video by dbtech

In this video and blog post we’re going to take a look at installing NextCloud on your OpenMediaVault server. When we’re done, you’ll be able to access your server from anywhere with an internet connection and you’ll be able to do it securely as we’re going to install a LetsEncrypt SSL for an added bit of security.

Be sure to read all the way through this blog post as it will explain the process as we go along.

Don’t skip anything. Each part is in here for a reason.

Prerequisites

  • You’ll need to have OMV5 installed. If you don’t have that, start here.
  • OMV needs to be on any port other than 80.
  • You’ll need a DuckDNS account.
  • You’ll need Docker AND Portainer installed.

If you don’t know how to setup a DuckDNS container, go watch this video.

Other Considerations

Because your OMV drive will most likely not be where you’ll want to store your files, you’ll want an additional hard drive mounted in your OMV setup. You’ll also want to set up a share on that drive and use SMB/CIFS to share the folder for use later in the setup.

Post Continues After This Ad Break:

Ad Break

Support DB Tech

Donations help me keep the channel running

Post Continues Here:

Getting started

Because NextCloud will need to run on port 80, we need to change the port that OpenMediaVault runs on. I’ve changed my OMV setup to port 81. You’ll also want to setup a static IP for your server. You can do this in the Network Interface settings in your OMV admin panel.

Once you’ve got that setup, you’ll need to do some port forwarding. You’ll need to forward ports 80 and 443 to your server’s IP address.

The Setup

Next, you’ll need to open a program like Putty to SSH into your server. Login as root. Once you’re logged in, you’re going to type the following:

nano docker-compose.yml

Press return and you should get a pretty blank screen. Copy and paste the following into the empty screen:

version: '3' 

services:

  proxy:
    image: jwilder/nginx-proxy:alpine
    labels:
      - "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true"
    container_name: nextcloud-proxy
    networks:
      - nextcloud_network
    ports:
      - 80:80
      - 443:443
    volumes:
      - ./proxy/conf.d:/etc/nginx/conf.d:rw
      - ./proxy/vhost.d:/etc/nginx/vhost.d:rw
      - ./proxy/html:/usr/share/nginx/html:rw
      - ./proxy/certs:/etc/nginx/certs:ro
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/tmp/docker.sock:ro
    restart: unless-stopped
  
  letsencrypt:
    image: jrcs/letsencrypt-nginx-proxy-companion
    container_name: nextcloud-letsencrypt
    depends_on:
      - proxy
    networks:
      - nextcloud_network
    volumes:
      - ./proxy/certs:/etc/nginx/certs:rw
      - ./proxy/vhost.d:/etc/nginx/vhost.d:rw
      - ./proxy/html:/usr/share/nginx/html:rw
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
    restart: unless-stopped

  db:
    image: mariadb
    container_name: nextcloud-mariadb
    networks:
      - nextcloud_network
    volumes:
      - db:/var/lib/mysql
      - /etc/localtime:/etc/localtime:ro
    environment:
      - MYSQL_ROOT_PASSWORD=toor
      - MYSQL_PASSWORD=mysql
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
    restart: unless-stopped
  
  app:
    image: nextcloud:latest
    container_name: nextcloud-app
    networks:
      - nextcloud_network
    depends_on:
      - letsencrypt
      - proxy
      - db
    volumes:
      - nextcloud:/var/www/html
      - ./app/config:/var/www/html/config
      - ./app/custom_apps:/var/www/html/custom_apps
      - ./app/data:/var/www/html/data
      - ./app/themes:/var/www/html/themes
      - /etc/localtime:/etc/localtime:ro
    environment:
      - VIRTUAL_HOST=your-subdomain.duckdns.org
      - LETSENCRYPT_HOST=your-subdomain.duckdns.org
      - [email protected]
    restart: unless-stopped

volumes:
  nextcloud:
  db:

networks:
  nextcloud_network:

The code above will do a number of things. First, it will download, setup, and install an nginx proxy server that we’ll use to access the server. Next, it will setup a LetsEncrypt SSL for your DuckDNS subdomain. After that, it will setup a mariadb container to store your data. Last, it will download and install the official NextCloud setup.

Note for Raspberry Pi Users

If you want to run this on a Raspberry Pi, you’ll need to change the database used in your Stack. You won’t be able to use MariaDB for this. you’ll need to change “mariadb” to “jsurf/rpi-mariadb” and then everything should work as expected.

Thanks to Gaurav Bafana for sharing this solution in the comments section on this YouTube video.

Back to the Setup

For the most part you can leave everything in that code as it is, but there are a few things that you’ll need to change.

The first thing to change is in the database area. Go back to the code and look for “MYSQL_ROOT_PASSWORD=toor” and change “toor” to a more secure password as it is the root password for the MySQL database server.

Next, you’ll need to change the “mysql” part of “MYSQL_PASSWORD=mysql”. Change “mysql” again to something more secure. Also, make note of this as you’ll need it later when we get to the setup screen for NextCloud.

You’ll also need to change the “VIRTUAL_HOST” and “LETSENCRYPT_HOST” to the subdomain URL that you setup on DuckDNS. Be sure to include the full URL (yourdomain.duckdns.org), not just the subdomain. Do NOT include http:// or https://

Lastly, you’ll put in your email address in the “[email protected]” as this is what Let’s Encrypt will use to register your SSL.

Once you’ve got all that changed, you can press CTRL+X to exit the editor. Be sure to press Y to say Yes, you want to save.

Getting Set Up

Now that you’ve got all that out of the way, you’re going to execute the docker-compose.yml file you just created by running this command:

docker-compose up -d

This may take a couple of minutes depending on your server hardware setup and your internet connection speed. Once it’s done, wait a couple of minutes as the SSL will take a bit to get setup. You can then go to your DuckDNS URL. So open your browser and type in https://yourdomain.duckdns.org

You should be presented with a NextCloud Installation screen.

Installing NextCloud

First things first, type in an admin username and password.

Below that, you’ll enter:

  • Database name: nextcloud
  • Database user: nextcloud
  • MySQL password you chose in the docker-compose file
  • The host needs to be changed from “localhost” to “db” (no quotes)

SMB Client Configuration Setup

Now login to Portainer and go int your containers area.

Find the container named “nextcloud-app” and look for the Console icon under “Quick Actions”. It’ll look like this: >_

On the page that pops up, click the blue “Connect” button.

You should see a console window. In that window, run each of these commands in order:

  • apt update
  • apt install libsmbclient-dev
  • pecl install smbclient
  • echo “extension=smbclient.so” > /usr/local/etc/php/conf.d/docker-php-ext-smbclient.ini
  • exit

Now go back to your SSH program and type: reboot now

Press return on your keyboard and give you system a minute to reboot.

Post Continues After This Ad Break:

Ad Break

Support DB Tech

Donations help me keep the channel running

Post Continues Here:

HTTPS Fix

This will fix some https issues and allow us to successfully connect our desktop and mobile apps to the server.

Login to your server as root using Putty. Type in:

nano /root/app/config/config.php

That will take you to a configuration file that you’ll need to edit. Add this to the end of the file:

'overwriteprotocol' => 'https',

It should look like this:

Upload Size Fix

Next we’ll fix a maximum file size upload issue.

In your Putty application, type this in:

find / -name "nginx.conf"

The screen will return several lines and will look something like this:

You’ll need to edit each of those nginx.conf files. In those files you’ll make sure that you add the following:

In the http {} part of the file, you’ll add:

client_max_body_size 0;

You’ll also add the following to JUST the /etc/nginx/nginx.conf  file:

server {
    client_max_body_size 0;
}

The end of each of your files (there will probably be 4 of them) should look similar to this:

Remember, ONLY add the “server client_max_body_size” snippet to the etc/nginx/nginx.conf file.

Change PHP.ini Upload Max

We’re going to repeat this process and edit the php.ini files on the server. This

Run this command:

find / -name "php.ini"

You should, again, find multiple php.ini files. You’re going edit each of them to have the following lines in them:

upload_max_filesize = 16G
post_max_size = 16G

Change .user.ini Upload Max

We’re going to repeat this process and edit the .user.ini files on the server.

Run this command:

find / -name ".user.ini"

You should, again, find multiple .user.ini files. You’re going edit each of them to have the following lines in them:

upload_max_filesize = 16G
post_max_size = 16G

NOTE:

These changes MAY get overwritten on NextCloud version updates so make note of these for future reference. linuckrox on Reddit added this bit of information on how you can move those modified files over to a container to prevent them from being overwritten by moving them to containers:

Installing Apps

At this point, everything should be working as intended. You should be able to download, install, and setup your desktop and mobile apps. The server address you’ll enter into each app will be your full DuckDns URL (https://yourdomain.duckdns.org)

Wrapping up

You’ve now got your own self-hosted file share and collaboration platform that you can access from anywhere with an internet connection. You can setup additional users as you need and you can finally cut the cord on services like DropBox, Google Drive, or wherever you’ve been storing your files online.

Giving Credit

Original Instructions found here