Linux Format

Build a Pi Nextcloud server

Christian Cawley has had enough of third-party cloud storage. Is a nextCloud-powered cloud server on Raspberry Pi the solution?

-

Christian Cawley has had enough of thirdparty cloud storage. Is a NextCloud-powered server on the Pi the solution? Yes.

Staying in control of your own data is vital. It goes deeper than personal data, too. All of those files and folders in your personal cloud storage with Google Drive, Dropbox, Box, Microsoft OneDrive and many others are subject to various degrees of – let’s say oversight – that you might not be entirely comfortabl­e with.

The solution is to run your own cloud server: a home-based storage system that can be accessed from anywhere. Available 24/7 for syncing data across your devices, mobile and desktop, such a server is best connected directly to your router for reliabilit­y. And you can do this with a Raspberry Pi and a suitably sized storage device. While several projects are available for building your own Raspberry Pi cloud server, perhaps the most complete solution is Nextcloud.

If you’re sick of paying for cloud storage or just find the whole idea a bit suspicious, self-hosting your own always-accessible cloud makes sense. With your own hardware and hosted on your own network, the cloud will be completely private. Throw in optional VPN support and even encryption to improve privacy. Selfhostin­g is also cheaper. For example, a 2TB drive on Amazon is considerab­ly cheaper than the same level of storage with Dropbox or Box.

Rolling your own home-based cloud storage solution will also give you faster speeds. You don’t need to rely on internet connection­s and put up with online traffic and virtual server bottleneck­s. The cloud is hosted on your own network, which means that you can sync data based on your router’s Ethernet or Wi-Fi speed.

Nextcloud solutions

Several cloud servers are suitable for Raspberry Pi. These include ownCloud, Nextcloud and Seafile. You can even do the whole thing from scratch with the Pi Cloud system, installing various server and VPN software to create a barebones cloud solution on Raspberry Pi OS.

Nextcloud has been chosen for this build. It comes with two installati­on options, configurat­ion is clear rather than esoteric, and it’s open source. When used on your own hardware, Nextcloud is also free to use.

There are three main options for installing Nextcloud on Raspberry Pi: the NextCloudP­i image, the Nextcloud Ubuntu appliance for Raspberry Pi, and manually installing on an existing Raspberry Pi OS installati­on.

While a Raspberry Pi 3 can be used, it’s considerab­ly slower than a Raspberry Pi 4. As such, the later Pi is recommende­d, with at least a 4GB SD card – 128GB cards are around £15. We ran NextCloudP­i on a Raspberry Pi 4 with 8GB of RAM and a 32GB SD card. You’ll also need a monitor and keyboard attached for the initial setup, although these can be detached, and the server ran as headless after configurat­ion. Ethernet is recommende­d for speed and reliabilit­y.

Get your Pi in the sky

You can take your pick of methods for installing Nextcloud on Raspberry Pi. NextCloudP­i is a preconfigu­red Nextcloud image for Raspberry Pi (and other SBCs) that features everything you need to manage your own cloud data server.

Built with Debian Buster and Nextcloud 19.0.2, NextCloudP­i has a setup wizard, web interface, dynamic DNS support, USB automount and everything else you might need to run a cloud server. It also supports Nextcloud mobile apps for mobile data syncing.

NextCloudP­i also offers a choice of installati­on options. You can install it the usual way with an image writing tool such as Etcher or Raspberry Pi Imager; install with Etcher and then move the boot partition to USB; flash direct to USB for use on a Raspberry Pi 4; or use

Berryboot to flash to SD or a USB device. This guide is more concerned with configurat­ion and use of a Nextcloud server on a Raspberry Pi with the standard SD card installati­on.

If you’re installing using the Raspberry Pi Imager, click Choose OS to select the downloaded IMG, Choose Storage to select your SD card, then Write. After flashing, boot the SD card in your Raspberry Pi and login with the Raspberry Pi OS default credential­s, these should be changed as soon as possible.

To use wireless networking, enter sudo raspi-config

and choose 2 Network Options. Select N2 Wireless LAN and choose the correct country, then enter your router’s SSID and password. Next, go to 5 Interfacin­g Options and enable SSH.

Exit raspi-config, then make a note of the IP address for wlan0 with ip addr . You can then access the Nextcloud server via SSH from another computer using

ssh pi@

The Pi can then be disconnect­ed from the display and monitor at any point now.

Either directly in the terminal or with an open SSH connection, enable the Nextcloud web interface:

sudo ncp-config

Select CONFIG then scroll to nc-webui. Erase the no and type yes instead, then Enter. Go Back, then Finish to exit. From your main computer, open https://:4443 in your browser, using the Pi’s IP address where specified. Login with the username ncp and the password ownyourbit­s. Copy or note the passwords for the web configurat­ion panel and the main web interface, then click Activate.

To use the Nextcloud web interface, open https:// [YOUR IP ADDRESS].

Ubuntu Appliance

Using Ubuntu Appliance (https://bit.ly/LXF280next­cloudappli­ance) is a more straightfo­rward approach. Start by writing the downloaded IMG file to your SD card with Raspberry Pi Imager (as above) or Etcher, then boot the Pi with the Nextcloud image.

While this starts up, configure your Ubuntu One account (see walkthroug­h, page 59, for details) for SSO (single sign-on) and storing encryption keys for SSH. Before proceeding, create SSH keys:

ssh-keygen -t rsa

Select where to store the key or tap enter to accept the default location. Input a passphrase when asked.

Retrieve the key using

cat ~/.ssh/id_rsa.pub

(Windows users can employ WinSCP to create an SSH key or open a terminal in Windows Subsystem for Linux and use the above commands.)

Copy the created key string into the SSH Keys page on your Ubuntu One account, then click Import SSH Key to save it.

On the Raspberry Pi, tap Enter when prompted. The next step is to configure networking. With Ethernet connected, simply move on to the next screen by highlighti­ng Done with the arrow keys and tapping Enter. If you’re using Wi-Fi, configure this instead.

Next, input your Ubuntu One email (see the walkthroug­h on page 59 again). Shortly after, the account should be verified and the IP address of your Nextcloud server displayed.

Along with the IP address, you should see your Ubuntu One SSO name. This can be used to access the Nextcloud server over SSH, in the style: username@.

Full access can be enjoyed via the browser. Using your main computer, open http://nextcloud.local in your browser (or the IP address displayed on your Raspberry Pi). Upon first access you’ll be prompted to create a

server administra­tor account. This is vital for the administra­tion of the Nextcloud server, enabling you to configure user access.

Terminal install

If you prefer to use your own Raspberry Pi OS for Nextcloud, it can be installed and set up in the terminal. Raspberry Pi OS Lite (https://bit.ly/lxf280-pioslite) is recommende­d for this.

Prerequisi­tes for this approach are the installati­on of the Apache, PHP and MySQL, along with some PHP modules: sudo apt install apache2 mariadb-server libapache2­mod-php sudo apt install php-gd php-json php-mysql php-curl php-mbstring php-intl php-imagick php-xml php-zip

Next, open the web folder:

cd /var/www/html

Check the download path (https://bit.ly/LXF280next­cloudlates­t) for the version of Nextcloud that you plan to use.

sudo wget https://download.nextcloud.com/server/ releases/nextcloud-xx.x.x.zip

When the download has completed, extract with:

sudo extract nextcloud-xx.x.0.zip

With this done, configure folder permission­s:

sudo chmod 750 nextcloud -R sudo chown www-data:www-data nextcloud -R

This ensures that anyone with an account can access your Nextcloud. You can then set up the MySQL database:

sudo mysql

Create the MySQL user nextcloud, ensuring that a strong password is set.

CREATE USER ‘nextcloud’ IDENTIFIED BY ‘password’; Next, create the database itself:

CREATE DATABASE nextcloud;

The nextcloud user should now be given all permission­s to the database, again changing ‘password’ to match the one you set earlier:

GRANT ALL PRIVILEGES ON nextcloud.* TO ‘nextcloud'@localhost IDENTIFIED BY ‘password’;

Finish with

FLUSH PRIVILEGES; quit

You should now be able to access the Nextcloud server from a desktop browser using the IP address of your Raspberry Pi, https:///nextcloud.

When prompted, create an administra­tor account, and input the credential­s for MySQL. Click Finish setup and wait while everything is finalised.

Changing clouds

With Nextcloud up and running on the Raspberry Pi, you can connect to it from any browser on your network (or beyond, with a static IP address from your ISP or a tool like No-IP or another dynamic DNS service). There’s even a mobile app for Android and iOS that can be used to sync files from your phone to the Pi-powered Nextcloud. If you don’t use the Play Store, the Android Nextcloud app is also available on F-Droid.

In the browser-based interface you’ll find a bunch of menus, presented like a cross between a smart TV and a typical cloud storage UI. From here you can upload files manually from your computer, or via a client tool – available for Linux, macOS and Windows. While command line configurat­ion options are available, everything you need to manage your Nextcloud is available in the browser.

Beyond the default photos, files, contacts, calendar and various other productivi­ty tools, Nextcloud can give you almost anything you need via a collection of programs. Some of these are preinstall­ed, others can be added in the Apps screen. This covers everything from tools like Collabora Online to new themes, social network integratio­ns, and much more.

To find out more, it’s worth taking the time to follow this tutorial with your preferred Nextcloud installati­on method and explore what’s available. Nextcloud has evolved into a vast and impressive cloud productivi­ty environmen­t. Consequent­ly, this guide only scratches the surface of what is possible with Nextcloud on a Raspberry Pi.

 ??  ?? Rather than leave a bare Raspberry Pi hosting Nextcloud on a table top, use a case with built in cooling and space for either a SATA HDD or SSD.
Rather than leave a bare Raspberry Pi hosting Nextcloud on a table top, use a case with built in cooling and space for either a SATA HDD or SSD.
 ??  ?? With Nextcloud running on your Raspberry Pi you can enjoy a selfhosted cloud storage, collaborat­ion and productivi­ty tool.
With Nextcloud running on your Raspberry Pi you can enjoy a selfhosted cloud storage, collaborat­ion and productivi­ty tool.
 ??  ?? Correct wireless configurat­ion enables you to place your Raspberry Pi Nextcloud appliance anywhere in your home or office.
Correct wireless configurat­ion enables you to place your Raspberry Pi Nextcloud appliance anywhere in your home or office.
 ??  ?? Images and videos uploaded or synced from your computer or phone can be viewed and managed in Nextcloud’s media player.
Images and videos uploaded or synced from your computer or phone can be viewed and managed in Nextcloud’s media player.

Newspapers in English

Newspapers from Australia