Turn Your Raspberry Pi 3 into a Personal Cloud Storage 2017
Our goal of installing ownCloud on the Raspberry pi is not just installing ownCloud but also mounting an external drive for lager capacity of data storage and to be able to access it from anywhere in the world as if you where using Dropbox or OneDrive.
OwnCloud is free robust open source software to set up your own syncing, Dropbox-like cloud storage..
Advantages: No monthly payments, added security and unlimited files storage. This process will always install the latest version of Owncloud.
This tutorial assumes that you have a fully functional Raspberry pi-3 with Raspbian (Full Desktop) installed with internet access, and a 8 GB Micro SD card Minimum!. If you haven’t installed Raspbian then check out my guide on how to install Raspbian via NOOBS.
There are many ways to install ownCloud onto a Raspberry Pi. If you don’t have a Raspberry PI I would personally recommend buying the Raspberry pi-3 kit with a 32 GB Micro SD card so that you don’t have to mount an external drive. Unless you want to store more than 32GB of data.
Setting up Raspberry Pi for Owncloud:
1. Turn on the Raspberry Pi. From the terminal or SSH enter the following command:
The following changes needs to be made in the Raspberry Pi configuration
a. Expand the root filesystem to have enough space for the cloud
Select “Expand Filesystem”
b. Change user password
“For Security when accessing form the WAN”
c. Change locale to en_US.UTF8
Select “Internationalisation Options”
d. Memory split, allocate 16M to video graphics
Select “Advanced Options” –> “Memory Split”
Go to owncloud.org and enter the commands as shown in the video. I would suggest to copy and paste the commands from owncloud so that you enter the following commands:
sh -c “echo ‘deb http://download.owncloud.org/download/repositories/stable/Debian_8.0/ /’ > /etc/apt/sources.list.d/owncloud.list”
wget -nv https://download.owncloud.org/download/repositories/stable/Debian_8.0/Release.key -O Release.key
apt-key add – < Release.key
apt-get install owncloud
Mount and Set up an External Hard Drive
These instructions are for mounting an NTFS formatted hard drive for maximum capacity storage, and allowing ownCloud to store files onto it.
1. For an NTFS drive we will need to install a NTFS package by entering the following:
sudo apt-get install ntfs-3g
2. Create a directory we can mount the drive to:
sudo mkdir /media/ownclouddrive
3. Create and add the www-data user to the www-data group:
sudo groupadd www-data sudo usermod -a -G www-data www-data
4. Make the user www-data owner of the mounted drive and make its permissions read, write and execute:
sudo chown -R www-data:www-data /media/ownclouddrive sudo chmod -R 775 /media/ownclouddrive
5. Now we need to get the gid, uid and the uuid as we will need to use them so the pi will remember it even if we plug it into a different USB port. Enter the following command for the gid:
id -g www-data
6. Now to get the uid enter the following command:
id -u www-data
7. We need to get the UUID of the attached external hard drive so the Pi can remember this drive even if you plug it into a different USB port.
ls -l /dev/disk/by-uuid
8. Then copy the light blue letters and numbers of the sda1 entry usually located on the bottom. It should look something like (numbers&letters -> ../../sda1). See picture below:
Auto mount the external drive and then check if it is accessible at /media/ownclouddrive:
9. Add your drive into the fstab file so it’ll boot with the proper permissions.
sudo nano /etc/fstab
10. Add the following line to the bottom of the file, updating the UUID with the values you got from the above step 5. (It should all be a single line)
UUID=xxxxxxxxx /media/ownclouddrive auto nofail,uid=33,gid=33,umask=0027,dmask=0027,noatime 0 0
11. Reboot the Raspberry Pi:
12. Now the external hard drive should automatically be mounted. If mounted we’re all good to go. To check it enter:
sudo ls /media/ownclouddrive
If there are files inside the drive you should be able to see them here. If it’s an empty drive you might not see anything so don’t be surprise if nothing shows up.
If you want to absolutely positive that the drive is properly mounted, unplug the drive from the RPI plug it onto a PC since it’s formatted NTFS it should be easily detected by the PC, open it, create an .txt file name it test, then eject it and plug it back to the RPI, reboot the RPI , and re-run the command:
sudo ls /media/ownclouddrive
The .txt file you created should be there.
Basic First Access Setup
1. Open your browser and enter the IP address provided, in my case is 18.104.22.168 you’ll be directed to your ownCloud storage server.
2. Because we installed SSL for more security you might get a certificate error, simply add the certificate to your exception list to proceed.
3. You should be presented with a simple setup screen, Here enter a username and password to create an admin account.
4. Click on Storage & database dropdown and enter your external hard drive: /media/ownclouddrive (Skip this if you didn’t setup an external drive).
5. Click Finish setup.
Done! !! all is left is to configure your devices to access your ownCloud storage.
Enable SSL for Secure External Access
This process only applies if you are planning on connecting to the Raspberry PI ownCloud from the WAN (outside the network) using mobile devices or tablet. Enable and configure SSL on Owncloud 9 in Raspberry PI ownCloud.
1. Open the terminal and run the following command:
sudo a2enmod ssl
2. Create a new directory for the self signed certificate:
sudo mkdir /etc/apache2/ssl
3. Create the self signed certificate and the server key that protects it, and placing both of them into the new directory:
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/owncloud.key -out /etc/apache2/ssl/owncloud.crt
Note: The above certificate is valid for 365 days. We have mentioned validity days in the command.
4. Now we need to setup the certificate:
sudo nano /etc/apache2/sites-available/default-ssl.conf
5. The lines that need changing are the following:
ServerName RPI IP :443 SSLEngine on SSLCertificateFile /etc/apache2/ssl/owncloud.crt SSLCertificateKeyFile /etc/apache2/ssl/owncloud.key
6. Activate the new virtual host
sudo a2ensite default-ssl
7. Restart apache
sudo service apache2 restart
Port Forward for External Access
Log into your router and get the WAN IP address:
Or Google what is my IP address?
Now we need to add the WAN IP to your trusted IP list and not to be overwritten by ownCloud. To do this open the Owncloud config file, enter:
sudo nano /var/www/owncloud/config/config.php
Here add the WAN IP (External IP address) you just got from the router or Google to the trusted domains array. Your new entry should look something like this:
1 => 'xxx.xxx.xxx.xxx',
X are just placeholders. Replace the X’s with the WAN IP Address.
Now update the URL of the overwrite.cli.url line with your WAN IP Address. It should look something like this:
'overwrite.cli.url' => 'https://xxx.xxx.xxx.xxx',
Here is an example of the completed config.txt file.
Once done save and restart the nginx service:
sudo service nginx restart
Now log into your router and navigate to the port forward section.
Now port forward SSL port 443 to the Raspberry pi internal IP (LAN IP) address and save settings.
Now your RPI ownCloud is ready to be accessed externally (WAN) and from your devices just download the ownCloud App and enter: “https:// WAN IP Address” on the address bar or devices. below is an example: