Convert your 35$ Raspberry Pi + OwnCloud into a DropBox Clone
To build your own private cloud storage (Dropbox alternative), ownCloud will need to be running on the Pi.
ownCloud is a self hosted Cloud storage that provides access to your data through a web interface or WebDAV while providing a platform to view, sync and share across devices easily—all under your control…ie Your own Dropbox 🙂
Security Footnote : ownCloud is best used to share files across the Internet. Sharing files across the Internet (that is, accessing ownCloud on your Pi from a remote location, such as your work) requires that you make your Pi “Internet facing” – by forwarding port 80 from your router. But before doing so, you should research and be aware of the attendant security risks and some of the measures needed to address them. A foot note at the bottom of the guide will give you a few pointers.
Strongly recommend using a Raspberry Pi 2 for this project. ownCloud will work with the older Pi models but might be slow.
- You will first need to configure your Pi to host a webserver.
- Install ownCloud
- Configure ownCloud.
Time and Difficulty :
- Time : 45 to 60 mins once you have the Raspbian Image file and the rest of the software.
- Newbie Difficulty level : Moderately easy ; Will need to use terminal and type in commands.
What you will need :
- Raspberry Pi 2 Model B or one of its clones like Banana Pi M1 or M2 or Banana Pro
- Ethernet connection or a supported USB Wifi adapter for the Pi
- SD or Micro SD Card that fits into your Pi (4GB or above is recommended)
- USB Keyboard and Mouse
- Connection to a TV or Monitor
You should seriously consider :
- Learning about SSH and how to remotely access the Pi from another machine on your network.
- Learning about Port forwarding settings for your Router.
STEP 1 : Update the Pi
Log in to Raspbian and enter the following commands with out the quotes :
sudo apt-get update sudo apt-get upgrade sudo apt-get dist-upgrade
The steps above will update the software and the raspbian distribution to the latest available.
reboot your pi with “sudo reboot“
STEP 2 : Build a Pi Webserver ( Step 1 is about 80% of the process and will take the better part of 2 hours)
STEP 3 : Install ownCloud and Associated Packages
To install ownCloud, we will enter commands at root level.
This needs to be done by logging in to Raspbian and typing in “
sudo -i “
To show that you are performing actions at root level, the terminal will display
Enter the following commands at root level :
wget -nv https://download.owncloud.org/download/repositories/stable/Debian_8.0/Release.key -O Release.key
apt-key add - < Release.key
sh -c "echo 'deb http://download.owncloud.org/download/repositories/stable/Debian_8.0/ /' >> /etc/apt/sources.list.d/owncloud.list"
(to create the file owncloud.list with the repository details)
(update the sources )
apt-get install owncloud
You will need to enter a new password twice for root during the mysql package installation.
Once all the packages are installed, your Pi is running the latest version of ownCloud
From a web browser on your network, go to the ip address of yourpi/owncloud ( eg. projpi.dyndns.com/owncloud or on your intranet via 192.168.x.xxx/owncloud)
You should be seeing your admin page to create your admin account at first run.
You now have fully functional OwnCloud server on your Raspberry Pi!
To point to webserver to load Owncloud as the default landing page, You will need to change the settings of Apache.
sudo nano /etc/apache2/sites-enabled/000-default.conf
Change the settings of DocumentRoot so that it reads
Press Ctrl+x to exit and save changes.
Owncloud should now load as the default landing page.
Recommended steps to follow through :
- Enable SSL and enforce logging in securely through https://yourserver.com/owncloud
- Move your data folder from the default SD card to an auto mounted HDD or USB drive.
Enabling SSL on your Raspberry Pi webserver
Enter the following commands at the terminal with out the quotes :
- “sudo -i” (to elevate to root from current user)
- “mkdir /etc/apache2/ssl ” (create the folder ssl under apache2)
- “openssl req -x509 -nodes -days 1095 -newkey rsa:2048 -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key ” (use openssl to generate a 3 year valid certificate in the folder created above). You will be asked to enter your data to fill out during the certificate creation. It is important that you give a FQDN – Fully Qualified Domain Name format for Common Name. ( eg. rpi.projpi.com)
- “ nano /etc/apache2/sites-available/default-ssl” (to use nano to edit file default-ssl and add in the newly created certificate and key to apache)
You are looking to replace the two lines below :
With the two lines below :
Press Ctrl+X to exit nano and “Y” to save changes to the file.
6. ” a2enmod ssl ” ( to enable ssl)
7. “a2ensite default-ssl “
8. “service apache2 restart ” (to restart apache2 )
You will now be able to access your ownCloud securely via https://youserver.com/owncloud (at log in time, your broswer nay give you a warning since you are using a self signed ssl certificate that has not been verified. Its ok to proceed )
Move your data folder from the default SD card to an auto mounted HDD or USB drive.
By default, ownCloud stores the data under its own folder which is in /var/www/owncloud. Since the Pi runs the OS on the SD card, it will soon run out of space once you start storing your data.
The only way to have a long term ownCloud Pi server is to have the data stored in a USB HDD or SDD.
Ext4 or Ext3 are native linux file formats and should be used on the data drive instead of opting for a drive with a NTFS or HFS or FAT formats.
To move data from within the ownCloud folder to an external USB drive, we need to perform the following steps
The HDD drive that will be used to hold the ownCloud data needs to be auto mounted so that it is available evertime the Pi boots up. This can be done by following these steps.
After completing the steps to automount a data drive, Enter the following commands at the terminal :
- “sudo -i” (to elevate to root privileges)
- “mkdir /media/data/ocdata” ( In the auto mounted HDD, make a folder called ocdata )
- “service apache2 stop” ( To stop the webserver)
- “nano /var/www/owncloud/config/config.php ” (use the nano editor to open config.php that resides in /var/www folder)
- In config.php change the line ‘datadirectory’ => ‘/var/www/owncloud/data‘, to ‘datadirectory’ => ‘/media/data/owncloud/data‘.Do not create a new folder called data under /media/data/owncloud/ yet. We will copy the existing data folder to the new location.
- “cp -R /var/www/owncloud/data /media/data/owncloud/data” ( copy recursively the data folder from /var/www/owncloud/data to /media/data/owncloud/data)
- “chown -R www-data:www-data /media/data/owncloud/data” ( to make sure permission and ownershop of the new data folder is with www-data)
- restart webserver by typing in “service apache2 restart“
You owncloud server now runs with a separate folder for its data on an automounted drive and connects with a secure ssl connection.