A couple years ago, I showed how to setup an ownCloud server on a Raspberry Pi. The system worked, but there were some performance hiccups. Most importantly was the ability for the system to handle large files and for the Pi v1 to take on the task in a speedy manner. I found myself using Microsoft’s OneDrive more often, electing to use their more proven platform for anything that didn’t require tight privacy controls and a firm handle on my data’s location. Still, it was a small, secure, and low-power cloud storage solution.
With the latest release of the Raspberry Pi 2Raspberry Pi 2, I thought this was a perfect time to update both my hardware and software in hopes of seeing performance improvements. The result gave ownCloud a whole new lease on life, at least in my lab. Check out my video showing the system and its performance:
I can’t be sure if it is the upgraded hardware, the updated linux OS and packages, changing to an nginx server, or the latest version of ownCloud, but the system worked much better. I had the server up and running within a few hours, and the web and desktop clients singing minutes after that. But the Pi2’s vastly improved specs have to be part of it:
Although things are greatly improved, it still can’t beat the usability of OneDrive. I tried creating issues for the system by uploading a 1GB file from ‘Computer A’ over a browser, uploading music files from ‘Computer B’ via the client, and quickly browsing the files from ‘Computer C’ over a browser. It worked for a while, but it had difficulty on the 1GB file upload and caused a sync error to flag on the client. Thankfully after a few minutes the system figured itself out and updated everything as one would hope. Stability and storage integrity is the ultimate goal so this is yet another example of trading patience/minor hassles for privacy.
I looked at some customizations like overclocking, but decided against it on account of stability trumping speed when it comes to data storage. Waiting a few seconds or even a minute for a webpage to load or a file to sync is annoying; having the system go down when a critical file is needed is simply unacceptable.
The ease of use, extremely low cost, and improved performance makes for a viable system when trying to control data and its privacy. With the new world of cloud-based systems everywhere it’s easy to forget that data is a tangible asset and must be considered as such!
While there are a few tutorials out there relating to Pi ownCloud servers, I couldn’t find one that was used with the Pi2 and OwnCloud v8 and solved all of my size limitation issues, so here are the steps that I followed to get the system installed and running.
Tutorial:
1. Follow Rpi’s getting started guide to install Raspian
2. Expand filesystem, set international options, Setup hostname and GPU memory split to 16, and enable ssh in the advanced options.
3. Update and upgrade the packages
4. Add users to the www-data group.
sudo usermod -a -G www-data www-data
5. Install nginx , OpenSSL, php5, etc… packages
sudo apt-get install nginx openssl ssl-cert php5-cli php5-sqlite php5-gd php5-common php5-cgi sqlite3 php-pear php-apc curl libapr1 libtool curl libcurl4-openssl-dev php-xml-parser php5 php5-dev php5-gd php5-fpm memcached php5-memcache varnish
6. Create the SSL certificate based on your location, organization, and email by running:
sudo openssl req $@ -new -x509 -days 730 -nodes -out /etc/nginx/cert.pem -keyout /etc/nginx/cert.key
7. Modify the privileges to the two cert files:
sudo chmod 600 /etc/nginx/cert.pem
sudo chmod 600 /etc/nginx/cert.key
8. Access the web server configuration file by running the command
sudo nano /etc/nginx/sites-available/default
9. Replace everything in the file with the following, replacing my Pi’s IP (10.0.0.124) with your own (I only put my Pi’s local IP here for security – you may have a global IP to allow you to access it anywhere on the 'net).
upstream php-handler {
server 127.0.0.1:9000;
#server unix:/var/run/php5-fpm.sock;
}
server {
listen 80;
server_name 10.0.0.124;
return 301 https://$server_name$request_uri; # enforce https
}
server {
listen 443 ssl;
server_name 10.0.0.124;
ssl_certificate /etc/nginx/cert.pem;
ssl_certificate_key /etc/nginx/cert.key;
# Path to the root of your installation
root /var/www/owncloud;
client_max_body_size 2000M; # set max upload size
fastcgi_buffers 64 4K;
rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect;
rewrite ^/carddav(.*)$ /remote.php/carddav$1 redirect;
rewrite ^/webdav(.*)$ /remote.php/webdav$1 redirect;
index index.php;
error_page 403 /core/templates/403.php;
error_page 404 /core/templates/404.php;
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ ^/(?:\.htaccess|data|config|db_structure\.xml|README) {
deny all;
}
location / {
# The following 2 rules are only needed with webfinger
rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
rewrite ^/.well-known/carddav /remote.php/carddav/ redirect;
rewrite ^/.well-known/caldav /remote.php/caldav/ redirect;
rewrite ^(/core/doc/[^\/]+/)$ $1/index.html;
try_files $uri $uri/ index.php;
}
location ~ \.php(?:$|/) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param HTTPS on;
fastcgi_pass php-handler;
}
# Optional: set long EXPIRES header on static assets
location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
expires 30d;
# Optional: Don't log access to assets
access_log off;
}
}
10. Edit php.ini file to allow 2GB file sizes by running the following and changing a couple parameters:
sudo nano /etc/php5/fpm/php.ini
search for upload_max_filesize and set it to 2000M
search for post_max_size and set it to 2000M
11. Configure PHP settings by running the following two commands and making the described changes in each file:
sudo nano /etc/php5/fpm/pool.d/www.conf
Then Change:
listen = /var/run/php5-fpm.sock
to :
listen = 127.0.0.1:9000
sudo nano /etc/dphys-swapfile
Then Change:
CONF_SWAPSIZE=100
to :
CONF_SWAPSIZE=512
12. Restart the Pi
13. Install owncloud by running the following commands and verify the files are in the right place:
sudo mkdir -p /var/www/owncloud
sudo wget https://download.owncloud.org/community/owncloud-8.0.2.tar.bz2
sudo tar xvf owncloud-8.0.2.tar.bz2
sudo mv owncloud/ /var/www/
sudo chown -R www-data:www-data /var/www
rm -rf owncloud owncloud-8.0.2.tar.bz2
14. Plug in the external hard drive (mine was formatted with NTFS).
15. Install the package to work with NTFS if your drive is setup as NTFS
sudo apt-get install ntfs-3g
16. Make a directory for mounting the drive
sudo mkdir /media/owncloud
17. Mount the drive (command below for NTFS drive)
sudo mount -t ntfs-3g -o uid=1000,gid=1000,umask=007 /dev/sda1 /media/owncloud
18. Find the UUID by running the following command. UUIS is the blue text associated with the sda1 drive that will look something like 4264E66D64E66361
ls -l /dev/disk/by-uuid/
19. Backup and then open fstab by running:
sudo cp /etc/fstab /etc/fstab.backup
sudo nano /etc/fstab
20. Edit fstab by adding the following at the bottom while replacing my UUID 4264E66D64E66361 with the one you found on your setup in step 18:
UUID=4264E66D64E66361 /media/owncloud ntfs-3g uid=1000,gid=1000,umask=007 0 0
21. Reboot the Pi and check that your drive has been automatically mounted.
22. Set permissions for the www-data group:
sudo usermod -a -G pi www-data
23. Navigate to cd /var/www/owncloud
24. Edit the .htaccess file to set the max file size:
sudo nano .htaccess
Then set the following values to 2000M:
Php_value upload_max_filesize
Php_value post_max_size
Php_value memory_limit
25. Edit the .user.ini file and change the following fields to 2000M:
sudo nano .user.ini
Then set the following values to 2000M:
upload_max_filesize
post_max_size
memory_limit
26. Reboot the Pi.
27. Visit the location of your Pi’s IP (mine was 10.0.0.124) with a browser to access your ownCloud Server and create an admin account! Note that without cURL installed, there may be an error for files over 4GB. But since this setup limits the files to 2GB, that’s no big deal.
28. Install ownCloud's free client/app on any of your machines, or elect you just use the browser interface.
29. Implement your favorite method of allowing access to your Pi2 from the internet. These steps vary from network to network and modem to modem, but here are a few resources that may help:
- Log into your router and forward port 22 to the Pi’s IP
- Configure the pi to accept port forwarding from step 3 of https://forum.owncloud.org/viewtopic.php?f=8&t=18742
- Check out No-ip.com which is a service that would help if the above doesn't work for you
NOTE: A comment from Nick Vee below that may be helpful to some users:
it was not pointing to the USB drive. The data was going on the sd card. There are a few steps missing to make sure the USB drive is being used. Make sure in /var/owncloud/config/config.php that the data directory is pointing to your USB mount point for your external disk. There is supposed to be a dialog for this in the admin setup, but I never saw it. Also the data directory on your USB must be owned by www-data (the web server user) so you have to set that permission with a chown command. There are examples of this in "how to move your data directory" in the owncloud forums.
Of course being an analog electronics guy, I am no linux wiz. I was able to put together this tutorial which is a variation of the following resources published by the real pros:
http://www.techjawab.com/2014/08/how-to-setup-owncloud-7-on-raspberry-pi.html
https://forum.owncloud.org/viewtopic.php?f=8&t=26005
Top Comments