Installing Nextcloud on Raspberry Pi 4 using Docker With Remote Access V1 – Episode 9

14, Feb 2021 | Raspberry Pi Series | 32 comments

Today we are going to be installing Nextcloud On Raspberry Pi 4. This is Episode 9 in our Raspberry Pi Series. If you haven’t watched our previous episodes then please do so first. This is so you can be up to date with this episode.

Nextcloud is an open-source self-hosted collaboration platform. It offers cloud features like Calendars, Contacts, file sharing and syncing. It also has an integrated app store where the system administrator can enable extra functionality like video conferencing and third-party API access.

Nextcloud is a fork of Owncloud. The Development team partied ways due to differing visions of where they wanted to take the platform. Nextclouds vision is to enable users to take back control over their data and communications from big data corporations.

Difficulty = Medium

Prerequisites:

You will need to have followed our previous episodes in our Raspberry Pi Series but if you just want to follow this guide we will give an overview of what you should already have:

Recommended USB Hard Drives:

WD 1TB My Passport Portable External Hard DriveWD 4 TB My Passport Portable External Hard Drive
USA Amazon Link:USA Amazon Link:
UK Amazon Link:UK Amazon Link:
We use Amazon Affiliate Links. At no extra cost to you. Thank you for using our links

So without further ado we are going to get started installing Nextcloud On Raspberry Pi 4.

Step 1 – Create the application folders:

The first thing we will need to do is set up two folders in our Appdata folder on our shared folder. The first folder we will call “nextcloud” and the second folder will be called “nextclouddb”.

Connect to your Pi via SSH and navigate to your Appdata folder by using the “cd” command.

cd /srv/dev-disk-DISKNAME/Appdata

Now we will create our “nextcloud” folder using the “mkdir” command.

mkdir nextcloud

Now we will do the same for our “nextclouddb” database folder.

mkdir nextclouddb

Step 2 – Create and deploy the Nextcloud Docker Stack.

Now both the folders needed have been created. Navigate to your Portainer interface and log in.

http://PIIPADDRESS:9000

Once logged in click on “Stacks” in the left hand menu. Then click on “Add Stack

Name your Stack anything that makes sense to you. In our example we named it “nextcloud“.

Copy the below docker-compose file and edit the values to match your configuration needs.

version: '2'

services:
  db:
    image: yobasystems/alpine-mariadb:latest
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    restart: always
    volumes:
      - /YOUR/FILE/PATH:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=YOURROOTPASSWORD
      - MYSQL_PASSWORD=YOURPASSWORD
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud

  app:
    image: nextcloud
    ports:
      - 8181:80
    links:
      - db
    volumes:
      - /YOUR/FILE/PATH:/var/www/html
    restart: always

Your stack should look similar to this:

When you have finished click on “Deploy the stack“. This can take some time to finish.

Once finished if you navigate to “Containers” on the left menu you should see two new containers.

One is the Nextcloud application and the other is the Nextcloud Maria database. You can check the logs by pressing the log button under “Quick actions” to check all is running correctly.

Step 3 – Adding Subdomain and Letsencrypt SSL certificate in NGINX Proxy Manager.

Now both containers are linked to communicate with each other it is now time to head to NGINX Proxy Manager to add the subdomain and container entry.

Once at the NPM dashboard click on “Proxy Hosts

Then “Add Proxy Host

Enter your subdomain under “Domain Names” and be sure to click “Add new ….” underneath so it saves the entry.

Navigate to Raspberry Pi’s IP address to “Forward Hostname/IP” section.

Then add the port you have assigned to the Nextcloud Docker. In our example we have used port “8181“.

Click the “Block Common Exploits” button so it turns green.

Your New proxy Host should now look similar to this:

Now press the “SSL” top menu.

Under “SSL Certificate” where it says “None” click then click on “Request a new SSL Certificate

Click on “Force SSL“, “HTTP/2 Support” and “I agree to the Let’s Encrypt Terms of Service“. Then click Save.

Once it completes successfully it will return to the Dashboard. You should now see your domain listed.

Please Note: There is a little bug here which we have to fix before proceeding.

You will need to go back into the edit settings by clicking the “hamburger menu” at the end of your domain section and click on “Edit“.

Then click on the “SSL” top menu.

Please ensure that both “Force SSL” and “HTTP/2 Support” are checked. If they have defaulted back then re-select them and click on “Save” again.

If you navigate to your Nextcloud install address using your domain name. You should now see the Installation page.

Please Note: Remember to use HTTPS.

https://nextcloud.YOURDOMAIN

You should also have a valid SSL/TLS certificate which you can confirm by using HTTPS as well as noticing the green padlock icon in the browser.

Step 4 – Installing Nextcloud On Raspberry Pi 4

Now we have completed all the prerequisite it is time to install Nextcloud. You should be at the Nextcloud installation screen within your browser.

Create a “Username” and “Password”.

Under “Storage & database” click the “drop-down icon” to open the hidden menu and select “MySQL MariaDB

Enter your MariaDB credentials that was set was set in the Nextcloud Stack. Replace “localhost” with “db“.

Important!! Notice: Untick “Install recommended apps” as having this checked can cause the installation to time out.

Click on “Finish setup” to complete the installation.

If all went well you should be greeted with the Nextcloud Dashboard Intro video which you can cross out of.

If you have any installation problems please read our Troubleshooting Installation Problems section below.

Step 5 – Finalizing Cloudflare

Now we have Nextcloud installed we have one final thing to do.

Log back into your Cloudflare account.

Once logged in head to the “DNS” tab. Under DNS management. Go to your CNAME used for your Nextcloud subdomain. Under “Proxy status” click on “DNS only” and change it to “Proxied“. Once set click on “Save“.

What this enables is the ability to mask your ISP provided public facing IP address if a reverse DNS lookup is done on your domain. This protects your privacy by hiding your location, your ISP as well as protecting your network against direct cyber attacks.

Anyone who does a reverse DNS lookup will see Cloudflare’s IP addresses and not yours :).

Troubleshooting Installation problems:

If you run into a timeout message like this:

It may be because you selected to install recommended apps during installation.

As it timed out you may also get a warning that the “The username is already being used” if you try to run the installer a second time.

This happens because, during the first run installation, the username set was added to the database. Even though the installation failed.

What you should do to resolve this is to use a new username and then rerun the installation. Once you are in the Nextcloud dashboard you can remove the unneeded admin account.

If you run into any other problems please let us know by commenting below or on our YouTube video’s comments.

We need your support.

We hope you enjoyed this episode and that it was helpful and you got benefit out of it.

If you did, please consider supporting our channel by Subscribing to our YouTube channel, and liking and sharing our content.

You can also make a donation via Paypal or become a Patreon if you wish to do so.

You can also follow us on Facebook or Twitter.

If you have any questions or any requests please ask in the comments below or on YouTube.

32 Comments

  1. gunth

    I never get past this point with the nginx ssl request, I keep getting the error
    [1/1/2021] [7:13:05 PM] [Express] ›⚠ warning Command failed: / usr / bin / certbot certonly –non-interactive –config” /etc/letsencrypt.ini “–cert -name “npm-3” –agree-tos –email “[email protected]…..” –preferred-challenges “dns, http” –domains “nextcloud.mydomain”
    I had this with my previous setup too, it drives me crazy
    When i go to nextcloud.mydomain get the correct site
    You’ve successfully started the Nginx Proxy Manager.

    If you’re seeing this site then you’re trying to access a host that isn’t set up yet.

    Log in to the Admin panel to get started.

    Reply
  2. gunth

    NS A / AAAA record (s) are correct
    i check it with lets’s debug.
    https://letsdebug.net/geekpi.be/467904
    Already 2 weeks that I am working on this.
    I think everything is right, is it my router or my vpn?
    I will definitely follow the rest of the videos but I will give this up for now.
    Thanks anyway for your effort and if you had to check the link, please remove it from your site afterwards

    Reply
  3. gunth

    ggot it to work.
    Deleted everything and started all over again.
    I used my local ip address instead of my public ip.
    Stupid of me, I’m good at linux and docker but not with networks.
    Now we can continue

    Reply
  4. Cleo

    My nextcloud stack seems to deploy with no issues but it does not create a container for it.

    Reply
    • Addicted2Tech

      It could be a permission’s problem. Have you followed the steps from Episode 1?. Maybe try removing the stack and trying to create it again.

      Reply
      • Cleo

        Yes i have created the user from step 1 and tried to re build the stack. The services will start but it is still not creating the container.

        These are the logs for nextcloud service

        AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 10.0.1.124. Set the ‘ServerName’ directive globally to suppress this message,
        AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 10.0.1.124. Set the ‘ServerName’ directive globally to suppress this message,
        [Fri Mar 05 20:53:16.009288 2021] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.4.16 configured — resuming normal operations,
        [Fri Mar 05 20:53:16.009689 2021] [core:notice] [pid 1] AH00094: Command line: ‘apache2 -D FOREGROUND’,

        And these are the logs for the nextcloud db service

        [i] mysqld not found, creating….,
        [i] MySQL directory already present, skipping creation,
        2021-03-05 20:53:13 0 [Note] /usr/bin/mysqld (mysqld 10.4.15-MariaDB) starting as process 1 …,
        2021-03-05 20:53:13 0 [Warning] You need to use –log-bin to make –binlog-format work.,
        2021-03-05 20:53:13 0 [Note] InnoDB: Using Linux native AIO,
        2021-03-05 20:53:13 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins,
        2021-03-05 20:53:13 0 [Note] InnoDB: Uses event mutexes,
        2021-03-05 20:53:13 0 [Note] InnoDB: Compressed tables use zlib 1.2.11,
        2021-03-05 20:53:13 0 [Note] InnoDB: Number of pools: 1,
        2021-03-05 20:53:13 0 [Note] InnoDB: Using generic crc32 instructions,
        2021-03-05 20:53:13 0 [Note] mysqld: O_TMPFILE is not supported on /var/tmp (disabling future attempts),
        2021-03-05 20:53:14 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M,
        2021-03-05 20:53:14 0 [Note] InnoDB: Completed initialization of buffer pool,
        2021-03-05 20:53:14 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().,
        2021-03-05 20:53:14 0 [Note] InnoDB: 128 out of 128 rollback segments are active.,
        2021-03-05 20:53:14 0 [Note] InnoDB: Creating shared tablespace for temporary tables,
        2021-03-05 20:53:14 0 [Note] InnoDB: Setting file ‘./ibtmp1’ size to 12 MB. Physically writing the file full; Please wait …,
        2021-03-05 20:53:14 0 [Note] InnoDB: File ‘./ibtmp1’ size is now 12 MB.,
        2021-03-05 20:53:14 0 [Note] InnoDB: Waiting for purge to start,
        2021-03-05 20:53:14 0 [Note] InnoDB: 10.4.15 started; log sequence number 61030; transaction id 21,
        2021-03-05 20:53:14 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool,
        2021-03-05 20:53:14 0 [Note] Plugin ‘FEEDBACK’ is disabled.,
        2021-03-05 20:53:14 0 [Note] InnoDB: Buffer pool(s) load completed at 210305 20:53:14,
        2021-03-05 20:53:14 0 [Note] Server socket created on IP: ‘::’.,
        2021-03-05 20:53:14 0 [Warning] ‘user’ entry ‘@143165bf75a9’ ignored in –skip-name-resolve mode.,
        2021-03-05 20:53:14 0 [Warning] ‘proxies_priv’ entry ‘@% [email protected]’ ignored in –skip-name-resolve mode.,
        2021-03-05 20:53:14 0 [Note] Reading of all Master_info entries succeeded,
        2021-03-05 20:53:14 0 [Note] Added new Master_info ” to hash table,
        2021-03-05 20:53:14 0 [Note] /usr/bin/mysqld: ready for connections.,
        Version: ‘10.4.15-MariaDB’ socket: ‘/run/mysqld/mysqld.sock’ port: 3306 MariaDB Server,

        Reply
        • cleo

          I think the issue was that I was trying to install on a node in a swarm. removed the node from the swarm and everything worked fine

          Reply
          • Alberto

            I have the same issue. I can’t understand how you solved the problem. Can you explain, please? What do you mean with “node in a swarm”? I’m a noob, yeah.

          • Patrick

            Hi, I got the same issue. How did you sort this out because like Alberto here, I don’t understand what you mean by ‘removed node from the swarm’

  5. sbc

    Hi noob here,
    I was wondering if you could help, I’ve recently installed npm along with Nextcloud on Docker on a Raspberry Pi. And I want to increase the maximum upload size from 512mb to 4096mb.
    Am I right on thinking that you change post_max_size = 8M & upload_max filesize = 2M?

    Ive found a couple of articles https://help.nextcloud.com/t/updating-max-upload-size-php-via-docker-compose/56922/2 and https://help.nextcloud.com/t/solved-nextcloud-with-docker-as-in-example-max-file-size-upload/21314 but they are a bit outdated, and it’s confusing to me and doesn’t make much sense.

    Reply
  6. Doug

    Ok, so this is where I really need help. I have spent yet another entire day trying to figure this out. I have followed every single one of your videos, on mutilple devices and ‘liked’ them all. I have given feedback to try to contribute in any way that I could. I don’t know what to do at this point. The first go around with your series, I used duckdns for the dynamic dns service and for the subdomains with nginx. It worked. After watching your video where you explained the benefits of using cloudflare, I took your advice and purchased a domain name with namecheap. I am doing exactly what you have done in the videos, with namecheap, cloudflare, nginx, everything. If I type my public ip address into any of my devices- multiple pi’s, laptop, phone, etc. I am able to reach the nginx landing page. When I type in my domain name, I get a 522 connection timed out error. It says browser working, cloudflare workin, host error. Obviously that means, the subdomains are not working either. I thought that maybe there were config issues somewhere that I was missing because I was using duckdns and then switched to cloudflare. I have tried hours of troubleshooting and I’m getting no-where. I finished the series so I had other containers like pi-hole. I switched them off, I tried using different dns servers in /etc/dhcp/resolv.conf, etc. Ufw is not running. fail2ban is not running. The cloudflare container updates my public ip correctly. I’m not seeing any errors anywhere except for in the nginx/data/logs/error.log which says 267 #267 connection refused while connecting to upstream, client 127.0.0,1, server: nginxproxymanager, request: “GET /api/ HTTP/1.1″…
    Ok, let me add that I have only leased this domain name for a little less than two days now but all the info is showing up in multiple dns lookups. I went to the same site you go to in the video and every single server on the map has my domain name except for one, only one server, located in the Netherlands and I am in the U.S. I went as far as to delete every one of my containers and I brought myself back to the beginning of the series and started it over. I had other containers that I created. I deleted the container, the image, the volumes, files, everything for a total of 22 containers! It took me weeks to do that but I wanted to eliminate any possibility I could think of. I am dedicated to learning this but I am hoplessly stuck right now. I apologize about this long message but I want to give you more than enough info. I need help with this…

    Reply
    • Doug

      I was really hoping to get a response back on this issue, maybe some guidance or something, especially since I have done everything that you have done in this series. Weeks later and I still have a new domain name purchased from namecheap, using cloudflare, and yet no website whatsover. Atleast I was getting somewhere before I made all these changes, now I’m getting nowhere.

      Reply
  7. Antonio Robles

    Hi great series! Thanks for your guide, I am following all the serie one by one and everything is going perfect until now… When I click on my domain(nextcloud.MYOWNDOMAIN.COM) from Nginx Proxy Manager to check if it works, it sends me to my own router. No matter if I try from within my own network or from outside, I mean, using my cellphone using 4G connection. Any ideas what I did wrong?. Thanks.

    Reply
    • Addicted2Tech

      Have you forwarded ports 80 and 443 on your Router to go to your Raspberry Pi IP?

      Reply
  8. Emule

    Dude Hi, everything is ok. Not that; During installation Nexcloud.mydomain.com database tabs deactivate. Therefore, I completed installation over 192.168.2.222:8181. When I want to open it through MyDomain after installation, he gave warnings outside the jurisdiction and passed it through /config/config.php. Nextcloud.mydomain.com SSL is actively opened on the last step page but not visible name and password boxes. The only problem is the input boxes that do not open.

    Reply
  9. Jeroen Smits

    Hi when I wanted to start nextcloud I got a page “Internal Error” The server was unable to process your request.
    And the ip adres from the computer I wanted to start Nextcloud.
    I did start from scratch with the installation with the same result.
    Can you give me direction where I have to solve this problem?

    Reply
  10. Yank's

    hi- firstly thanks for the detailed explaination. i am now stuck at nextcloud login page. while creating a new username and password with the MSQL database filled same as yours. upon executing i recv below error. i am noob to the system. pls assist

    Error
    Error while trying to create admin user: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [1045] Access denied for user ‘nextcloud’@’172.20.0.2’ (using password: YES)

    Reply
    • Khal

      I am getting the same error. Any fix found for this please?

      Reply
    • Gozrid

      Instead of using yobasystems/alpine-mariadb:latest

      try:
      yobasystems/alpine-mariadb:10.4.17

      It should work then.
      Its a problem with a library that doesnt work with raspbian stable and therefore the container does not have the correct time.

      Reply
  11. moji

    regardless of what I try, in the initial login I always get:
    nextcloud Error while trying to create admin user: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] Connection refused

    Any idea how to solve that?
    Thanks in advance

    Reply
  12. JT

    Hello, Been enjoying the series, very helpful. However,at this point, Nginx Proxy Manager won’t create the SSL. It has an internal error. I can access nextcloud via HTTP but not HTTPS. Any idea why the certbot fails? I would assume I have my dns records in cloudflare correct if I can use nextcloud with HTTP but could be wrong. The subdomain does not have proxy on and SSL/T:S in on full in Cloudflare.

    Reply
    • George

      Hello. I have exactly the same problem. If i try to create a new certificate i get internal error. I can access the subdomain without the SSL certificate.

      Did you managed to fix it?

      Reply
  13. Luca

    Hi, I’ve accidentally picked SQLite db, how can I change to MySQL? I tried to cancel the container but when I re-launch the stack obviously the application remind my mistake… do you know what folder or file I’ve to erase from the raspberry to completely clean the installation and have a fresh restart? I can’t find the path where the folder is stored

    Reply
  14. mjeshurun

    Thank you for this great tutorial.
    I would like to use your explanation to create a NextCloudPi docker/portainer stack.
    Could you please explain what Docker Compose code I should use to make it work?

    This is the docker compose code the creator of NextCloudPi shared for docker installation:

    version: ‘3’
    services:
    nextcloudpi:
    image: ownyourbits/nextcloudpi
    command: “${IP}”
    ports:
    – “80:80”
    – “443:443”
    – “4443:4443”
    volumes:
    – ncdata:/data
    – /etc/localtime:/etc/localtime:ro
    container_name: nextcloudpi
    volumes:
    ncdata:

    I’m a noob, but it appears to me this docker compose code, does not take into account your method of using mysql and nginx.

    Could I please ask that you tell me what docker compose code I should use to install NextcloudPi using your method?

    I understand I need to change the code the creator of NextcloudPi shared, but, unfortunately, I don’t know how to do that 🙁

    Reply
  15. Bob

    I found the following at:

    https://www.higithub.com/jlesage/issue/docker-nginx-proxy-manager/203

    It corrected the internal error when requesting the ssl certificate!

    This was an issue that kept me down for a day. Not sure if this was your issue or not but:

    My DNS for my domain is Cloudflare. Cloudflare recently changed to require an API key that is not the global one.

    Sign in to Cloudflare Click your profile at the top right API Tokens Create Token Edit zone DNS Click “Use Template” Permissions: N/A Zone Resources: [Include] [All zones] Click “Continue to summary”

    You will get your API Key, save this and treat it like a password.

    Now go to the web gui for Nginx Proxy Manager.

    Add Proxy Host > Details (fill out for what you need) > SSL

    SSL Certificate [Request a new SSL Certificate] Force SSL: on Use a DNS Challenge: on DNS Provider: Cloudflare Credentials [# Cloudflare API token dns_cloudflare_api_token = replace with your API Key] “I Agree to the Let’s Encrypt Terms of Service”: On Save

    This should leave you with an Online working proxy.

    Reply
  16. Alex

    Hello!
    I installed nextcloud using your instruction and almost everything works perfect.
    I have very irritating error “Error when assembling chunks, status code 504” every time I try to upload files 1.0 Gb or more. Any thoughts how to get rid of this error?
    Thanks in advance!

    Reply
  17. Ahmed

    Thanks a lot for this.
    I managed to set up nextcloud, but when I try to access it again, it gives me this error:

    This page isn’t working
    ‘my_domain’ redirected you too many times.
    Try clearing your cookies.
    ERR_TOO_MANY_REDIRECTS

    Could you advise?

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

<a href="https://www.addictedtotech.net/author/attadmin/" target="_self">Addicted2Tech</a>

Addicted2Tech

We love technology and enjoy sharing helpful FREE content for others to enjoy. We believe in community. If you like what we do please support us by sharing and liking our tutorials & Subscribing to our YouTube channel. You can also follow us on social media.

Support Our Work!

Donate Via Patreon

Raspberry Pi 4 Model B [8GB] RAM Single Board Computer

Last update on 2022-12-02 / Affiliate links / Images from Amazon Product Advertising API

CanaKit Raspberry Pi 4 Extreme Kit – 128GB Edition (4GB RAM)

Last update on 2022-12-02 / Affiliate links / Images from Amazon Product Advertising API

We Are An Affiliate!

Just so you know, we may collect a share of sales or other compensation from the links on this page. As an Amazon Associate I earn from qualifying purchases.

The Affiliate link recommendations come at no extra cost to you.

We hope you love the products we recommend!

Thank you if you use our links, we really appreciate it!

Related Posts