Saturday, September 28, 2019

Raspberry Pi 4 as a Cloud Server

I've bought Raspberry Pi 4 to use it as a DaaS (Desktop as a Service). I've needed a VPN server to securely connect to when I am traveling. I've needed a Cloud Server to replace Dropbox to have unlimited space. I've needed a NAS (Network-attached storage) to share files among mu laptops and computers. I've also needed a Music Player Server to manage my music files and serve as a source for my amplifier. I've also needed a media player like Apple TV to play my movies, youtube etc.

In summary Raspberry Pi as:
1. Cloud server (this post)
2. VPN server
3. NAS
4. Music server
5. Media Player



To be able to do all of the above, I think it is better to keep the original Raspbian distribution.

I have used Nextcloud:
I have used an external hard drive to the Raspberry Pi (rp). Since there is a chance that when you restart your rp it automatically mount external hard drive to different place it is a good idea to configure fstab to make sure that it always mounted on the right place. I also set static ip for rp (192.168.0.101)

Installing Nextcloud:
    sudo apt install snapd
    sudo snap install nextcloud

Setting up the external hard drive:
    sudo mkdir /media/pi/cloud

select UUID of your external hard drive:  
    sudo blkid
    sudo emacs /etc/fstab

Use tab for each column when you add the following:
UUID=YOURS /media/pi/cloud       auto    nosuid,nodev,nofail     0       0

Now reboot to see it mounts the external drive properly at the right place.

Now edit the configuration file:
sudo emacs /var/snap/nextcloud/current/nextcloud/config/autoconfig.php

change the data directory as:
'directory' => '/media/pi/cloud'

Start nextcloud:
sudo snap restart nextcloud.php-fpm

To install a Let's Encrypt SSL certificate, type:
sudo nextcloud.enable-https lets-encrypt  
If you use public dynamic dns services like noip remember to add it to config:
sudo emacs /var/snap/nextcloud/current/nextcloud/config/config.php
'trusted_domains' =>
  array (
    0 => '192.168.0.101',
    1 => '192.168.0.*',
    2 => 'YOURS.ddns.net',
  ),

check the directory file in the config if it is set to the right place

'datadirectory' => '/media/pi/cloud',