In this tutorial we will install the latest version of the Raspberry Pi OS, Install Nextcloud, add external storage and secure with a self assigned SSL.
If you find this tutorial helpful please consider donating
Paypal : egon@wiredzero.com
Download the latest PI OS
https://www.raspberrypi.org/software/operating-systems/
Download Disk Imager
Windows Download
https://sourceforge.net/projects/win32diskimager/
Mac Download
https://www.balena.io/etcher/
Optional Wifi
Create a file called wpa_supplicant.conf and paste in the following
country=us
update_config=1
ctrl_interface=/var/run/wpa_supplicant
network={
scan_ssid=1
ssid="wifiname"
psk="yourwifipassword"
}
Copy the wpa_supplicant.conf to root of sd card labeled boot
Create empty text file called ssh and copy it to root of sd card labeled boot
Open disk imager program and write the image to the SD card to be used by the PI
Insert the sd card into pi, power on and locate on your local network
ssh into pi using powershell or terminial
ssh pi@yourlocalip
username : pi
default password : raspberry
Change default pi password
sudo passwd pi
Now lets create a new user
sudo adduser egon
Give sudo rights to new user
sudo usermod -aG sudo egon
Update the raspberry pi os
sudo apt-get update
sudo apt-get upgrade
Reboot the pi
sudo reboot
Log back in with new user in my case was egon and edit the raspi-config file
sudo raspi-config
Change timezone to yours
Install webserver, database server and all required libraries
sudo apt install apache2 mariadb-server libapache2-mod-php -y
sudo apt install php-gd php-json php-mysql php-curl php-mbstring php-intl php-imagick php-xml php-zip -y
Install Nextcloud
go to https://nextcloud.com/install/#instructions-server
Copy link
https://download.nextcloud.com/server/releases/nextcloud-22.1.0.zip
In terminal change to the following directory
cd /var/www/html
Type in sudo wget then paste in the link you copied from Nextcloud
Example
sudo wget https://download.nextcloud.com/server/releases/nextcloud-22.1.0.zip
Now unzip the file, make sure you have the correct version
sudo unzip nextcloud-22.1.0.zip
Now change ownership/permissions
sudo chmod 750 nextcloud -R
sudo chown www-data:www-data nextcloud -R
Create the database for nextcloud to use
sudo mysql
CREATE USER 'nextcloud' IDENTIFIED BY 'password';
CREATE DATABASE nextcloud;
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@localhost IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
quit
sudo reboot
change default root directory for apache2
cd /etc/apache2/sites-available
sudo nano 000-default.conf
Change
DocumentRoot /var/www/html/
To
DocumentRoot /var/www/html/nextcloud
Reboot the pi
sudo reboot
open nextcloud in browser by going to local ip of the pi and create admin account.
Add the external storage plugin in nextcloud
# Mounting
# create a mount point
cd /media
sudo mkdir pstorage
show all uid's
cut -d: -f1,3 /etc/passwd
show all gid's
getent group
sudo blkid
sudo nano /etc/fstab
UUID=908D-CDD4 /media/pstorage auto defaults,uid=33,gid=33 0 2
sudo mount -a
reboot
Log back in and type the following to check if drive is mounted
df -h
Open nextcloud in browser
Enable external storage
Add mount point to external storage.
/media/pstorage
Secure nextcloud with SSL
sudo mkdir -p /etc/apache2/ssl
Generate the certificate:
sudo openssl req -x509 -nodes -days 365 -newkey rsa:4096 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt
Enable SSL Module for Apache:
sudo a2enmod ssl
sudo systemctl restart apache2
Modify the configuration file:
LOG BACK INTO PI IN TERMINAL
cd to
cd /etc/apache2/sites-available
sudo nano default-ssl.conf
Change to
DocumentRoot /var/www/html/nextcloud
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key
control o and control x to exit
Enable default SSL and restart apache
sudo a2ensite default-ssl.conf
sudo service apache2 restart
Force SSL usage on NextCloud:
sudo nano /etc/apache2/sites-available/000-default.conf
put right above
ErrorLog ${APACHE_LOG_DIR}/error.log
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
sudo a2enmod rewrite
sudo service apache2 restart
sudo reboot
Now open Nextcloud in your browser and check for SSL