Build a better Nextcloud
Christian Cawley shows you how to get the most out of your Raspberry Pi-powered Nextcloud server.
Christian Cawley demonstrates how to get the most out of your Raspberry Pi-powered Nextcloud server.
Running your own cloud storage server saves money, allows you to expand storage as necessary, and can be done with a device as small as a Raspberry Pi. Our previous guide to setting up a Nextcloud server on the Raspberry Pi (LXF280) covered everything you need to know about installing and setting up NextCloudPi and the Nextcloud Ubuntu Appliance, as well as the manual installation of Nextcloud on Raspberry Pi OS.
But with the software installed and connected to your network, the job is only half-done. You still need to configure it for your specific use-case, enable external storage to reduce wear and tear on the Pi’s SD card, and make the Nextcloud server accessible from beyond your home network.
The most straightforward way to set up external access to Nextcloud and to add external storage is to do it with the NextCloudPi installation.
External storage
The Raspberry Pi 3 and 4 boot from the SD card. While this can be changed in favour of a more reliable USB device, SD is the default option.
This has obvious advantages, from speed and convenience to simplicity. However, there is a key disadvantage, which is the longevity of the card: regular reading and writing of data to the SD card will shorten its lifespan.
Throw into the mix the fact that your NextCloudPi storage installation is limited to the size of the microSD card in your Raspberry Pi and you have an obvious problem. It’s just not big enough to compete with Dropbox or OneDrive or Google Drive, and you’re limited to the maximum supported capacity of 1TB.
Adding an external disk drive to Nextcloud requires only a device with USB connectivity (unless you’re using a case with a SATA adapter) . For faster data transfer, use USB 3.0+ devices, and for the optimum, rely on SSD or NVME/M.2 flash.
First, connect the USB device and then set up an SSH terminal to your Nextcloud and enter
sudo mkdir /media/USBstorage
In your computer’s web browser visit the NextCloudPi web panel (using the 4443 port, so https://[IP ADDRESS]:4443) and start the wizard if it doesn’t launch automatically by clicking the wand icon in the toolbar. Select USB Configuration, input Yes, then Continue, and Format USB.
When this completes, select ‘Move data to USB’. You now have a Raspberry Pi-powered Nextcloud server that can store as much data as you need without wearing out the microSD card.
Static access
Configuring Nextcloud to be accessed from devices beyond your network (such as your mobile device while shopping) is possible with a static IP address. But before setting this up for external access, it’s smart to configure the Raspberry Pi with a static IP address for access within your network – and, more crucially, your router – first.
To confirm the Pi’s IP address and how it was assigned, open a terminal or SSH connection and enter
ip r | grep default
If you see the letters dhcp the IP address is assigned dynamically by the router. Make a note of the IP address, then check the nameserver or DNS IP:
sudo nano /etc/resolv.conf
Make a note of the IP address listed here for the nameserver before proceeding. Setting a static IP address can be achieved by editing the dhcpcd.conf file in nano:
sudo nano /etc/dhcpcd.conf
Add the following lines to the end of the file, changing the capitalised text with the information you have to hand:
interface NETWORK static ip_address=STATIC_IP/24 static routers=ROUTER_IP static domain_name_servers=DNS_IP
Change NETWORK to eth0 or wlan0 , depending on the network type (Ethernet or Wi-Fi).
For STATIC_IP enter the IP address you wish to use for the Pi – it’s smart to use the one already assigned to maintain connectivity.
For ROUTER_IP , use the gateway IP for the router on your network – this address is usually printed on the router.
Finally, set DNS_IP to the IP address you made a note of after checking the resolv.conf file. Finish by rebooting with
sudo reboot
Confirm the changes with Ctrl+X, then Y and Enter, and reboot. You can check the static IP address has been applied using
ip r | grep default
If you can’t get a static IP address from your ISP – and many of them don’t provide one (see boxout) – your best option for accessing the Nextcloud from anywhere is with a dynamic DNS provider.
Access anywhere
Start by accessing your NextCloudPi web panel and enter the credentials you used during setup.
In the web panel, find Networking and select ‘letsencrypt’ from the menu. Add a working email address when prompted and click the wand icon to launch the setup wizard and select ‘External access’. Answer Yes, then wait for setup to complete. When prompted for Port forwarding, choose ‘I will do it manually’.
You’ll need to forward ports 443 and 80 (for HTTPS and HTTP) to the Raspberry Pi, targeting the routerassigned IP address for the device or its hostname ( nextcloudpi ). How you do this will differ from router to router. Many routers offer an online help tool, but you can also refer to the device’s documentation to find out how to use port forwarding.
In the next screen, sign up to FreeDNS when prompted, select Subdomains and choose a free domain and subdomain, then input your router’s public IP address (check by searching Google for ‘what is my IP’) and Save.
Next, choose Dynamic DNS and copy the Direct URL for your subdomain into a text file. Remove everything before (and including) the ? so you’re left with a long alphanumeric string. On the FreeDNS screen in NextCloudPi, complete the Domain field with the subdomain you chose, then paste the alphanumeric hash from the text file into the Update Hash field and click Finish to complete.
With your Nextcloud installation now fully online it should be accessible from the mobile app or any other device through your browser.
Note that by establishing a static IP you may need to create a new connection in whichever version of the Nextcloud app you’re using.
Enhance with apps
With the Nextcloud server accessible from anywhere, there are a few things you can do to take it to the next level. Almost all those things can be found in the apps list. These were mentioned in the previous tutorial but there are several that can really enhance your Raspberry Pi cloud server if you’re planning on using it for a home file and media server.
In the Featured Apps list, you’ll find a list of snaps that are listed by type. In the Multimedia tab you’ll find apps for playing media. There is also an app called Automated Media Conversion which converts media files using FFmpeg based on rules that you set. It can also convert files as they’re uploaded.
Antivirus and anti-ransomware apps can also be installed to protect your cloud data, along with integrations with mainstream cloud solutions. This is useful for easily migrating your cloud storage across rather than downloading to a PC and then uploading to the Nextcloud server.