Personal Cloud on Raspberry Pi using NextCloud and Ubuntu

Personal Cloud on Raspberry Pi using NextCloud and Ubuntu

I bought a Raspberry Pi about 8 months ago, back in december 2020. I bought it because, I wanted to learn linux and I was bored because of the lockdown. I didnt know exactly what to do with it for a month after I got it. So, I kept programming and re-programming it for many things - ESXi, raspian OS etc. Finally, I liked two projects that I liked. One is using it with TV as a retro game console by installing retropi on it. The other is to use it as a NAS device for home. I tried many different NAS software available for Pi, but I liked nextcloud the most. Reasons can be found here.

Two more reasons for choosing nextcloud are:

  1. On premise cloud storage. Data is saved locally on the user hard drive or SSD and not on some remote DC across the world
  2. I can still use my Raspberry Pi as an NFS/CIFS host in addition of nextcloud which is a win in my opinion

In the beginning, it was an experiment, but now, its a full fledged data storehouse for my family and me. My family members are using nextcloud to back up their data from their desktops, laptops, phones, and tabs.

So, lets list down my objectives that I want to achieve out of this project:

  1. Ability to sync files from multiple computers, phones and tabs
  2. Ability to use NFS/CIFS shares to back up data that doesnt support nextcloud synching. e.g. backup of Windows C drive data using a backup tool called Cobian backup that I use at home. And, timeshift backup of my Linux Desktop. Technically, they both can be done using nextcloud synch but I dont want to use that
  3. Every user should have their own space and their files should not be accessibly by another user. Now, here is where nextcloud has a serious access concern. I am the administrator of this application in my house and therefor that admin account has access to ALL the files stored on the HDD used by Nextcloud. As a workaround, I created one more non admin user for myself to keep my files separate and that user doesnt see the files of the other family members. Admin user has the visibility to the files, but I dont use it. Also, I have informed my family that I can access ALL their files but I wont in good faith
  4. All of this must be done over wifi

Things I used to set this whole thing up

  1. Raspberry Pi (RPi). I am using the 8GB 4th gen RPi. It can be purchased here. https://tinyurl.com/RPi8GB
  2. A microSD card to install the Ubuntu OS on RPi
  3. A desktop PC running Ubuntu. Windows and Mac can also be used
  4. A 5TB WD MyPassport portable HDD. Any capacity HDD/SSD/Pendrive can be used as alternative

High Level Process

  1. Download and install on the desktop RPi imager from https://www.raspberrypi.org/software/
  2. Write the Ubuntu desktop 64 bit image to a micro SD card
  3. Install Ubuntu desktop 64 bit OS on RPi
  4. Install MariaDB
  5. Install Nextcloud
  6. Configure Nextcloud

We will go into details on steps 4, 5, and 6. For 1, 2, and 3, I will keep it short.

Low Level Process

Install Ubuntu desktop OS on RPi

I tried this process with Ubuntu server edition on RPi, but I ran into a wifi network bug which was a show stopper for me. So, after spending hours trying to fix and then failing, I decided to just use Ubuntu desktop edition instead of server edition.

So, basically, once the RPi imager software is downloaded and installed on the desktop, insert the microSD card in your desktop and write the Ubuntu image to it. Here are a few screenshots to help.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Once the OS image is written to the microSD card, take it out of the desktop and insert it into the RPi. Connect a monitor to the RPi using the HDMI cable and power it on. RPi will go thru the process of installing Ubuntu OS. This is a very basic install. It only asks for wifi name, timezone, hostname, a new user name and password. I could not take any screenshots as it was getting installed on a Pi and there is no way to take screenshots except using a camera or an external hdmi capture device. I named the device nextcloudpi, user is lordvader, and timezone for me is India Standard Time (IST).

Once Ubuntu is installed, assigning a static IP address to the wifi interface is recommended. I assigned 192.168.1.19 to my RPi. I, in fact hard coded my RPi's IP address as 192.168.1.19 in my home router using MAC binding. The reason for doing this is so that nextcloud always runs on one IP address and RPi can be easily managed headless.

Connect Wifi

root@nextcloudpi:~# nmcli d?


DEVICE? ? ? ? ?TYPE? ? ? STATE? ? ? ? ?CONNECTION??


wlan0? ? ? ? ? wifi? ? ? disconnected? ? ?--?


p2p-dev-wlan0? wifi-p2p? disconnected? --? ? ? ? ??


eth0? ? ? ? ? ?ethernet? unavailable? ?--? ? ? ? ??


lo? ? ? ? ? ? ?loopback? unmanaged? ? ?--? ? ??


?


root@nextcloudpi:~# nmcli r wifi on?


root@nextcloudpi:~# nmcli d wifi list??


IN-USE? BSSID? ? ? ? ? ? ? SSID? ? ? ? ? ? ?MODE? ?CHAN? RATE? ? ? ? SIGNA>?


? ? ? ? ?98:DA:C4:D5:CD:2C? Thanos? ? ? ? ? ?Infra? 9? ? ?405 Mbit/s? 90? ?>?


? ? ? ? 18:45:93:6A:FB:89? Thor? ? ? ? ? ? ?Infra? 1? ? ?130 Mbit/s? 89? ?>?


?


root@nextcloudpi:~# nmcli d wifi connect thor password 123456?


root@nextcloudpi:~#??


root@nextcloudpi:~# nmcli dev?


DEVICE? ? ? ? ?TYPE? ? ? STATE? ? ? ? ?CONNECTION??


wlan0? ? ? ? ? wifi? ? ? connected? ? ?Thor? ? ? ??


p2p-dev-wlan0? wifi-p2p? disconnected? --? ? ? ? ??


eth0? ? ? ? ? ?ethernet? unavailable? ?--? ? ? ? ??


lo? ? ? ? ? ? ?loopback? unmanaged? ? ?--? ? ? ? ??


root@nextcloudpi:~#??


root@nextcloudpi:~# ping google.com?


PING google.com (142.250.195.78) 56(84) bytes of data.?


64 bytes from maa03s38-in-f14.1e100.net (142.250.195.78): icmp_seq=1 ttl=118 time=10.8 ms?


64 bytes from maa03s38-in-f14.1e100.net (142.250.195.78): icmp_seq=2 ttl=118 time=10.3 ms?


^C?


--- google.com ping statistics ---?


2 packets transmitted, 2 received, 0% packet loss, time 1001ms?


rtt min/avg/max/mdev = 10.257/10.521/10.786/0.264 ms?


root@nextcloudpi:~#??        

Update all the apps by running and install openssh-server. This will enable us to ssh into RPi from this point on to stick to our principles of headless configuration and management

sudo apt update
sudo apt upgrade
sudo apt install openssh-server        

I installed some optional apps: vim, htop, and net-tools

sudo apt-get install vim
sudo apt-get install htop
sudo apt-get install net-tools        

Configure External Storage

This is very important. We need NextCloud to write to an external storage device. By default, it writes to the FS where its installed, which is the microSD card in this case. This is okay for testing, but is not a good idea for production. So, in my case, I want to use my external 5TB WD MyPassport portable HDD, which I will configure now.

  1. Connect the HDD via USB to RPi
  2. ssh to RPi from desktop

ssh 192.168.1.19        

  1. Run fdisk to determine the device ID of the HDD. Its /dev/sda1 in my case

oot@nextcloudpi:~#?fdisk?-l?

?

Disk /dev/sda: 4.55 TiB, 5000947302400 bytes, 9767475200 sectors?

Disk model: My Passport 2627?

Units: sectors of 1 * 512 = 512 bytes?

Sector size (logical/physical): 512 bytes / 4096 bytes?

I/O size (minimum/optimal): 4096 bytes / 4096 bytes?

Disklabel?type:?gpt?

Disk identifier: E8AC28FE-CE08-4493-802E-50C2BDD7BE00?

??

Device???? Start??????? End??? Sectors? Size Type?

/dev/sda1?? 2048 9767473151 9767471104? 4.5T Microsoft basic data?        

4. Mount the HDD to the path /var/www/nextcloudpi/data. This path is very important as you will see later on in the article. /var/www is where nextcloud install files will be and because, it uses install_folder/data as the data folder, we want to use this path as the mount point for our HDD. Also, put it in fstab so its permanent. At this point, also create a user that has sudo privileges if not done already.

root@nextcloudpi:~# mkdir /var/www/nextcloudpi/data?

root@nextcloudpi:~# mkfs.ext4 /dev/sda1?


Type Y to proceed?


root@nextcloudpi:~# mount /dev/sda1 /var/www/nextcloudpi/data?



root@nextcloudpi:~# vim /etc/fstab?


/dev/sda1 /var/www/nextcloudpi/data ext4 defaults 0 0?



Create a user if it doesnt exist and allow it to use sudo:?


?adduser lordvader?


?Usermod –aG sudo lordvader?


Reboot the server?        

5. Download Nextcloud application from their website www.nextcloud.com. Go to the website, click Get Nextcloud, select Server packages and copy the download link. We will use wget to actually download it to the Pi. I downloaded it in my downloads directory as shown:

lordvader@nextcloudpi:/$ cd /home/lordvader/Downloads/?


lordvader@nextcloudpi:~/Downloads$??


lordvader@nextcloudpi:~/Downloads$??


lordvader@nextcloudpi:~/Downloads$ wget https://download.nextcloud.com/server/releases/nextcloud-22.0.0.zip?


--2021-08-02 16:46:35--? https://download.nextcloud.com/server/releases/nextcloud-22.0.0.zip?


Resolving download.nextcloud.com (download.nextcloud.com)... 95.217.64.181, 2a01:4f9:2a:3119::181?


Connecting to download.nextcloud.com (download.nextcloud.com)|95.217.64.181|:443... connected.?


HTTP request sent, awaiting response... 200 OK?


Length: 172627889 (165M) [application/zip]?


Saving to: ‘nextcloud-22.0.0.zip’?


??


nextcloud-22.0.0.zip? ? ? 100%[===================================>] 164.63M? 6.72MB/s? ? in 24s? ? ??


??


2021-08-02 16:46:59 (7.00 MB/s) - ‘nextcloud-22.0.0.zip’ saved [172627889/172627889]?


??


lordvader@nextcloudpi:~/Downloads$??        

Install MariaDB

Nextcloud supports many Databases for its operations, but recommends MySQL/MariaDB for performance. https://tinyurl.com/DBSEL

Command to install MariaDB:

lordvader@nextcloudpi:~/Downloads$ sudo apt install mariadb-server?


[sudo] password for lordvader:??


Reading package lists... Done?


Building dependency tree... Done?


Reading state information... Done?


.?


.?


.?


Setting up mariadb-client-10.5 (1:10.5.10-0ubuntu0.21.04.1) ...?


Setting up mariadb-server-10.5 (1:10.5.10-0ubuntu0.21.04.1) ...?


Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /lib/systemd/system/mari?


adb.service.?


Setting up mariadb-server (1:10.5.10-0ubuntu0.21.04.1) ...?


Processing triggers for man-db (2.9.4-2) ...?


Processing triggers for libc-bin (2.33-0ubuntu5) ...?


lordvader@nextcloudpi:~/Downloads$??        

Let's now initialize MariaDB

lordvader@nextcloudpi:~/Downloads$ sudo mysql_secure_installation?


??


NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB?


? ? ? SERVERS IN PRODUCTION USE!? PLEASE READ EACH STEP CAREFULLY!?


??


In order to log into MariaDB to secure it, we'll need the current?


password for the root user. If you've just installed MariaDB, and?


haven't set the root password yet, you should just press enter here.?


??


Enter current password for root (enter for none):??        

This password is NOT the linux root password. This is the root pwd for the mariaDB instance. We havent set it up yet, so just press enter.

Whats happening below:?

  • create root password?
  • Remove anonymous user as we wont use it. Bad for security?
  • Disallow remote login for root – we wont allow it. Bad for security?
  • Remove the test DB – as MariaDB recommends to remove test DB before moving the server to production?
  • Apply settings by reloading the privilege table?

Enter current password for root (enter for none):?

OK, successfully used password, moving on...

?

Setting the root password or using the unix_socket ensures that nobody

can log into the MariaDB root user without the proper authorisation.

?

You already have your root account protected, so you can safely answer 'n'.

?

Switch to unix_socket authentication [Y/n] n

... skipping.

?

You already have your root account protected, so you can safely answer 'n'.

?

Change the root password? [Y/n] Y

New password:?

Re-enter new password:?

Password updated successfully!

Reloading privilege tables..

... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone

to log into MariaDB without having to have a user account created for

them.? This is intended only for testing, and to make the installation

go a bit smoother.? You should remove them before moving into a

production environment.

?

Remove anonymous users? [Y/n]?

... Success!

?

Normally, root should only be allowed to connect from 'localhost'.? This

ensures that someone cannot guess at the root password from the network.

?

Disallow root login remotely? [Y/n]?

... Success!

?

By default, MariaDB comes with a database named 'test' that anyone can

access.? This is also intended only for testing, and should be removed

before moving into a production environment.

?

Remove test database and access to it? [Y/n]?

- Dropping test database...

... Success!

- Removing privileges on test database...

... Success!

?

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

?

Reload privilege tables now? [Y/n]?

... Success!

Cleaning up...

?

All done!? If you've completed all of the above steps, your MariaDB

installation should now be secure.

?

Thanks for using MariaDB!

?

lordvader@nextcloudpi:~/Downloads$?
        

Lets now configure MariaDB. We will now create a DB to be used by Nextcloud. I am naming it nextclouddb. After that I have granted all privileges to manage this DB to the user nextclouddb and password mypassword. BTW, this is where I made a mistake by naming the user nextclouddb. I intended it to be nextclouduser, but made a mistake and realized it much later down the road. Its not a problem as far as operations go, so I left it as it is.

lordvader@nextcloudpi:~/Downloads$ sudo mariadb

Welcome to the MariaDB monitor.? Commands end with ; or \g.

Your MariaDB connection id is 52

Server version: 10.5.10-MariaDB-0ubuntu0.21.04.1 Ubuntu 21.04

?

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

?

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

?

MariaDB [(none)]> CREATE DATABASE NEXTCLOUDDB;

Query OK, 1 row affected (0.001 sec)

?

MariaDB [(none)]> SHOW DATABASES;

+--------------------+

| Database?????????? |

+--------------------+

| NEXTCLOUDDB??????? |

| information_schema |

| mysql????????????? |

| performance_schema |

+--------------------+

4 rows in set (0.002 sec)

?

MariaDB [(none)]> GRANT ALL PRIVILEGES ON nextclouddb.* TO 'nextclouddb'@'localhost' IDENTIFIED BY 'mypassword';?????????? -----> Thsi password is a new one and will manage the DB, so remember it save it, make it complex

Query OK, 0 rows affected (0.007 sec)

?

MariaDB [(none)]> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.002 sec)

?
        

Then press ctrl+d to exit.

Next, let's install apache2 which Nextcloud will use to provide web services. The following command installs apache2 alongwith other required packages

sudo apt install php php-apcu php-bcmath php-cli php-common php-curl php-gd php-gmp php-imagick php-intl php-mbstring php-mysql php-zip php-xml
        

Verify that apache is installed and running

lordvader@nextcloudpi:~/Downloads$ dpkg --list | grep apache

ii? apache2??????????????????????????????????? 2.4.46-4ubuntu1.1??????????????????????????????????????????????????? arm64??????? Apache HTTP Server

ii? apache2-bin??????????????????????????????? 2.4.46-4ubuntu1.1??????????????????????????????????????????????????? arm64??????? Apache HTTP Server (modules and other binary files)

ii? apache2-data?????????????????????????????? 2.4.46-4ubuntu1.1??????????????????????????????????????????????????? all????????? Apache HTTP Server (common files)

ii? apache2-utils????????????????????????????? 2.4.46-4ubuntu1.1??????????????????????????????????????????????????? arm64??????? Apache HTTP Server (utility programs for web servers)

ii? libapache2-mod-php7.4????????????????????? 7.4.16-1ubuntu2.1??????????????????????????????????????????????????? arm64??????? server-side, HTML-embedded scripting language (Apache 2 module)

lordvader@nextcloudpi:~/Downloads$?

?

?

lordvader@nextcloudpi:~/Downloads$ systemctl status apache2

● apache2.service - The Apache HTTP Server

???? Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)

???? Active: active (running) since Mon 2021-08-02 17:11:16 IST; 1min 5s ago
        

Now, visit the webpage by entering the Raspberry Pi's IP in the browser address bar. It should show the default apache page.


No alt text provided for this image

Run this command to install recommended extensions for PHP

lordvader@nextcloudpi:~/Downloads$ sudo phpenmod bcmath gmp imagick intl

[sudo] password for lordvader:?
        

Install NextCloud

Switch to the directory where nextcloud was downloaded and unzip it. Then, move the extracted directory to /var/www. Also, lets change the ownership of this directory to www-data which is an apache user.

Unzip:

lordvader@nextcloudpi:~/Downloads$ sudo unzip nextcloud-22.0.0.zip?

lordvader@nextcloudpi:~/Downloads$ ll

total 168600

drwxr-xr-x? 3 lordvader lordvader????? 4096 Aug? 2 19:21 ./

drwxr-x--- 16 lordvader lordvader????? 4096 Aug? 2 16:45 ../

drwxr-xr-x 13 root????? root?????????? 4096 Jul? 6 02:28 nextcloud/

-rw-rw-r--? 1 lordvader lordvader 172627889 Jul? 6 02:30 nextcloud-22.0.0.zip

        

Change Ownership to www-data:

lordvader@nextcloudpi:~/Downloads$ ls -l

total 168592

drwxr-xr-x 13 root????? root?????????? 4096 Jul? 6 02:28 nextcloud

-rw-rw-r--? 1 lordvader lordvader 172627889 Jul? 6 02:30 nextcloud-22.0.0.zip

lordvader@nextcloudpi:~/Downloads$?

lordvader@nextcloudpi:~/Downloads$?

lordvader@nextcloudpi:~/Downloads$ sudo chown -R www-data:www-data nextcloud

lordvader@nextcloudpi:~/Downloads$ ll

total 168600

drwxr-xr-x? 3 lordvader lordvader????? 4096 Aug? 2 19:21 ./

drwxr-x--- 16 lordvader lordvader????? 4096 Aug? 2 16:45 ../

drwxr-xr-x 13 www-data? www-data?????? 4096 Jul? 6 02:28 nextcloud/

-rw-rw-r--? 1 lordvader lordvader 172627889 Jul? 6 02:30 nextcloud-22.0.0.zip

lordvader@nextcloudpi:~/Downloads$        

Move directory:

?   
lordvader@nextcloudpi:~/Downloads$ sudo mv ./nextcloud /var/www

lordvader@nextcloudpi:~/Downloads$?

lordvader@nextcloudpi:~/Downloads$ cd /var/www

lordvader@nextcloudpi:/var/www$ ll

total 16

drwxr-xr-x? 4 root???? root???? 4096 Aug? 2 19:25 ./

drwxr-xr-x 15 root???? root???? 4096 Aug? 2 17:09 ../

drwxr-xr-x? 2 root???? root???? 4096 Aug? 2 17:11 html/

drwxr-xr-x 13 www-data www-data 4096 Jul? 6 02:28 nextcloud/

lordvader@nextcloudpi:/var/www$?        

Disable the default site. https://www.linux-commands-examples.com/a2dissite

lordvader@nextcloudpi:/var/www$ sudo a2dissite 000-default.conf?

Site 000-default disabled.

To activate the new configuration, you need to run:

? systemctl reload apache2

lordvader@nextcloudpi:/var/www$?

lordvader@nextcloudpi:/var/www$?

lordvader@nextcloudpi:/var/www$ sudo systemctl reload apache2
        

Lets rename the nextcloud folder to nextcloudpi so its unique. This is not absolutely needed, but I did it to keep my website name unique, in case I decide to host it to be available over internet in the future

lordvader@nextcloudpi:/var/www$ ll

total 16

drwxr-xr-x? 4 root???? root???? 4096 Aug? 2 19:25 ./

drwxr-xr-x 15 root???? root???? 4096 Aug? 2 17:09 ../

drwxr-xr-x? 2 root???? root???? 4096 Aug? 2 17:11 html/

drwxr-xr-x 13 www-data www-data 4096 Jul? 6 02:28 nextcloud/

?

lordvader@nextcloudpi:/var/www$ sudo mv nextcloud/ nextcloudpi

lordvader@nextcloudpi:/var/www$?

lordvader@nextcloudpi:/var/www$?

lordvader@nextcloudpi:/var/www$ ll

total 16

drwxr-xr-x? 4 root???? root???? 4096 Aug? 2 19:30 ./

drwxr-xr-x 15 root???? root???? 4096 Aug? 2 17:09 ../

drwxr-xr-x? 2 root???? root???? 4096 Aug? 2 17:11 html/

drwxr-xr-x 13 www-data www-data 4096 Jul? 6 02:28 nextcloudpi/

lordvader@nextcloudpi:/var/www$?
        

Lets create a config file for our new nextcloud site (I like vim, but essentially any text editor can be used):

sudo vim /etc/apache2/sites-available/nextcloudpi.conf?
<VirtualHost *:80>

???? DocumentRoot "/var/www/nextcloudpi"

???? ServerName nextcloudpi

?

???? <Directory "/var/www/nextcloudpi/">

???????? Options MultiViews FollowSymlinks

???????? AllowOverride All

???????? Order allow,deny

???????? Allow from all

??? </Directory>

?

??? TransferLog /var/log/apache2/nextcloudpi_access.log

??? ErrorLog /var/log/apache2/nextcloudpi_error.log

?

</VirtualHost>
        

Lets enable the new site now, but dont reload apache2 just yet:

lordvader@nextcloudpi:/var/www$ sudo a2ensite nextcloudpi.conf

Enabling site nextcloudpi.

To activate the new configuration, you need to run:

? systemctl reload apache2

lordvader@nextcloudpi:/var/www$?
        

Lets configure PHP according to https://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize.

Filename to edit is /etc/php/7.4/apache2/php.ini. Enter/edit the following fields by searching for them.

memory_limit = 512M
upload_max_filesize = 20G?
max_execution_time = 360
post_max_size = 20G?
date.timezone = Asia/Kolkata
opcache.enable=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=1
        

Install some recommended mods and finally reload apache service:

lordvader@nextcloudpi:/var/www$ sudo a2enmod dir env headers mime rewrite ssl

Module dir already enabled

Module env already enabled

Enabling module headers.

Module mime already enabled

Enabling module rewrite.

Considering dependency setenvif for ssl:

Module setenvif already enabled

Considering dependency mime for ssl:

Module mime already enabled

Considering dependency socache_shmcb for ssl:

Enabling module socache_shmcb.

Enabling module ssl.

See /usr/share/doc/apache2/README.Debian.gz on how to configure SSL and create self-signed certificates.

To activate the new configuration, you need to run:

? systemctl restart apache2

lordvader@nextcloudpi:/var/www$?

lordvader@nextcloudpi:/var/www$ sudo systemctl reload apache2
        

At this point, verify that apache services are running properly. If not, check the configuration done so far.

lordvader@nextcloudpi:/var/www$ sudo systemctl status apache2

● apache2.service - The Apache HTTP Server

???? Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)

???? Active: active (running) since Mon 2021-08-02 17:11:16 IST; 2h 39min ago
        

Nextcloud Configuration

Now, we can get to the meat of the project, NEXTCLOUD.

Launch the website from the browser with IP address of the raspberry pi. In my case, it is 192.168.1.19

And you should see the nextcloud landing page. We will now configure some options here. Remember our external 5TB hard drive. That's the one we want to configure over here otherwise data will keep going to the default directory in the SD card of raspberry pi.

  1. Create an administrator user. This user has access to ALL data from ALL users. If other people are going to use nextcloud for data storage, they should be informed that their data is visible to the administrator. This is a net new user, so give it any name. I am going to call it cloudadmin
  2. Configure data folder. This is very important. If we leave it at default, the data will go to /var/www/nextcloudpi/data which is not ideal as it is on the SD card on raspberry pi. We want to use our external HDD/SSD. In my case, i am going to use a 5TB WD My Passport HDD as I want all my family members to use nextcloud and save all of their data here
  3. The path to data folder in my case is: /var/www/nextcloudpi/data which is a mount point of my external HDD. I have made it permanent mount using /etc/fstab earlier
  4. Configure database details:

  • DB user: nextclouddb
  • Password: That was created earlier while configuring MariaDB (mypassword)
  • DB Name: The new DB that we created earlier – nextclouddb
  • Hostname: localhost is fine
  • Keep checked "Install recommended apps" and then click Finish setup

No alt text provided for this image

Once the GUI setup is finished and you see the landing page, here is what the data folder will look like. This means that this directory will be used as data root directory. 5TB of NAS running at home with Google Drive/ Onedrive like functionality. WOOHOO!

root@nextcloudpi:/var/www/nextcloudpi/data/nextcloudpi/data#?

root@nextcloudpi:/var/www/nextcloudpi/data/nextcloudpi/data# ll

total 20

drwxrwx--- 4 www-data www-data 4096 Aug? 2 20:35 ./

drwxrwxrwx 3 www-data www-data 4096 Aug? 2 20:21 ../

drwxr-xr-x 8 www-data www-data 4096 Aug? 2 20:35 appdata_oc0xhsu8hwfm/

drwxr-xr-x 3 www-data www-data 4096 Aug? 2 20:33 cloudadmin/

-rw-r--r-- 1 www-data www-data? 542 Aug? 2 20:33 .htaccess

-rw-r--r-- 1 www-data www-data??? 0 Aug? 2 20:33 index.html

-rw-r--r-- 1 www-data www-data??? 0 Aug? 2 20:35 nextcloud.log

-rw-r--r-- 1 www-data www-data??? 0 Aug? 2 20:33 .ocdata

root@nextcloudpi:/var/www/nextcloudpi/data/nextcloudpi/data#?

root@nextcloudpi:/var/www/nextcloudpi/data/nextcloudpi/data#?
        

Enable local memory cache by editing the config.php file in /var/www/nextcloudpi/config. Add the line "'memcache.local' => '\OC\Memcache\APCu'," at the end. Paste everything in double quotes as it is (without the double quotes of course). This file should be owned by root user and www-data group.

https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/caching_configuration.html

root@nextcloudpi:/var/www/nextcloudpi/config# cat config.php
<?php
$CONFIG = array (
? 'instanceid' => 'oc0xhsu8hwfm',
? 'passwordsalt' => '58q1po+Q/uRmx1LrvD7vQmMHvaizOx',
? 'secret' => 'jyy3CfX+Uurf31FiHtI1e5ZPOi8TQ0Y/LIefQ5tPAxjpsxkF',
? 'trusted_domains' => ?
? array (
??? 0 => '192.168.1.19',
? ),
? 'datadirectory' => '/var/www/nextcloudpi/data/nextcloudpi/data',
? 'dbtype' => 'mysql',
? 'version' => '22.0.0.11',
? 'overwrite.cli.url' => 'https://192.168.1.19',
? 'dbname' => 'nextclouddb',
? 'dbhost' => 'localhost',
? 'dbport' => '',
? 'dbtableprefix' => 'oc_',
? 'mysql.utf8mb4' => true,
? 'dbuser' => 'nextclouddb',
? 'dbpassword' => '1234',
? 'installed' => true,
? 'memcache.local' => '\OC\Memcache\APCu',
);
root@nextcloudpi:/var/www/nextcloudpi/config# ?


root@nextcloudpi:/var/www/nextcloudpi/config# chmod 660 config.php?

root@nextcloudpi:/var/www/nextcloudpi/config#?

root@nextcloudpi:/var/www/nextcloudpi/config# chown root:www-data config.php?        

At this point, we have a fully functional cloud storage solution, but we now need to create users on this application and then distribute the username/password to the family members. They can change their password themselves after the first login.

Login to the web gui using the IP address of the RPi and admin user that was created above. In my case, I named it cloudadmin.

Click on the profile icon in top right corner and click on users

No alt text provided for this image

Click on new user and then follow the prompts to create that user. Here, you can set up a quota for the user. Default and unlimited quota mean the same thing. 5 and 10 GB are too less. I am looking into how we can get a more reasonable number here. There must be a setting that I am not aware of right now. For now, just choose default quota

No alt text provided for this image

Now log out as admin user and log in as the new created user

Then, click on top right corner again on the profile picture and click settings.

On this page, you can change the following:

  • Profile pic
  • Email ID – for password resets and notification

Dashboard shows status, weather and recommended files. This can be customized by clicking the customize button there. I removed recommended files from mine as it looks cluttered to me and I also changed the wallpaper.?

No alt text provided for this image

Under files, all the files are listed categorized in user created folders

Under photos, all the photos will be shown in a nice gallery like design. Its beautiful but slow especially on a low power device like pi

Under activity, the user can view a nice sequence of work performed e.g. uploaded a file, downloaded a file etc.

Client Side Configuration

Now, install a desktop application which can be downloaded from nextcloud website. Since I am using linux, I downloaded the linux app image and then installed it. However, nextcloud supports a variety of OS and devices:

  • PC – Linux, Windows, Mac
  • Android – phone and tab
  • IOS – iPhone and iPad

The compatibility can be checked on www.nextcloud.com

After installation, and starting nextcloud, it presented me with a login dialog

No alt text provided for this image

Select login?to your nextcloud

Then, enter the url of the nextcloud that we set up earlier on raspi. In my case, the IP is 192.168.1.19

No alt text provided for this image

After this, it will open a tab in the browser and ask the user to confirm log in. This is why its important to log in as the intended user in the browser before installing the desktop client.

Once the web page prompts are completed, the dialog box will show the account to be connected and show the folder to be synced. (It shows a warning in my case, because this is 20th time I tried this and I have too many nextcloud folders, but this should not happen in a normal case)

No alt text provided for this image

After this, nextcloud will sync all files of this user on the server to this desktop and show a task bar icon in which it can be further customized. This is the place where other folders from a PC can be added to sync. In my case, I have many folders that I want to sync and is impossible to list down here, but its a very straightforward process and works exactly like onedrive/dropbox/google drive.

No alt text provided for this image

And, in a similar fashion, I set up nextcloud on my android phone and tablet too. Each of my family members now have an account on nextcloud and they are safely backing up all of their data to the 5TB HDD that is attached to the Raspberry pi. In addition, since the OS installed on Pi is linux, I have also created some NFS/CIFS shares on which we all can dump files if we don’t want to sync them. This is very useful for large files that don’t need syncing, but still need to be moved away from the PC storage to a central location from where it can be picked up by other family members. Example: Movies and Music and family pictures. Very useful.

And since all this is running off a low power raspberry pi, I can leave it running 24x7 and my electricity bills don’t shoot up at all. I have done a calculation and raspberry pi + HDD running 24x7 is consuming around 100 INR per month, which is not too much in my opinion.

So, there you have it folks. Nextcloud is an amazing cloud storage service. Its free of cost, reliable, and can be installed on a low powered device like Pi. It wins from other NAS solutions in the sense that all the files are hosted locally in your HDD in your control. All the files are saved as flat files, which means that even if the SD card gets corrupted, you will still have your data intact and readable without nextcloud. And in my opinion, it wins against similar cloud offerings just because the data is local and still accessibly over LAN and internet (if configured that way) and in the long run, is much cheaper than cloud offerings for home use. It may not be as reliable though, because the data is going to a single HDD which can fail and take the data down with it. Hope that never happens.

要查看或添加评论,请登录

Kamal Gupta的更多文章

  • How to Install Dockers - Linux

    How to Install Dockers - Linux

    These days, the words "dockers" and "kubernetes" are very common to hear if you work in IT. Many applications are…

    2 条评论
  • Configure Swap Space and Hibernation in Linux

    Configure Swap Space and Hibernation in Linux

    Typically, swap space is something that is taken care of during the server deployment, however, there are situations in…

  • DNS Server Config CentOS 8

    DNS Server Config CentOS 8

    1. Configure the firewall firewall-cmd --permanent --zone=public --add-service=dns firewall-cmd --reload 2.

    3 条评论

社区洞察

其他会员也浏览了