Wall's Corners Wall's Corners Author
Title: Raspberry Pi OwnCloud: Your Own Personal Cloud Storage
Author: Wall's Corners
Rating 5 of 5 Des:
In this project we’re going to make a Raspberry Pi Owncloud server this can act as your very own personal cloud storage. As the protection ...

In this project we’re going to make a Raspberry Pi Owncloud server this can act as your very own personal cloud storage.

As the protection of your privacy becomes harder and harder you may be thinking of moving your files to a private cloud storage. If this is the case the then this tutorial is perfect for you. It is important to remember that since your data will be stored on your local network you will end up with using more bandwidth if uploading and downloading files from outside your network.

In this tutorial will take you through everything you need to know to get it setup and accessible.

If you’re curious and want to learn more about Owncloud be sure to check out their website over atOwncloud.org.

If you’re a visual person and would like to see our video on how to put this together then check out our video below. It will take you through everything you need to know get your Raspberry Pi Owncloud server up and running.

Equipment

I used the following equipment for this personal cloud storage setup.

Required

Optional

Note:  It is highly likely that the USB ports on the Raspberry Pi will be unable to power an external hard drive so you may need to invest in a powered USB hub.

Setting up The Raspberry Pi Owncloud Server

Firstly, you will need to have a Raspberry Pi with installed. If you haven’t installed then check out our guide on how to install Raspbian via NOOBS (New Out of the Box Software).

There are quite a few ways you’re able to install Owncloud onto your Raspberry Pi. In this particular tutorial we’re going to be downloading a web server (nginx) and Owncloud.

  1. Firstly, in either The Pi’s command line or via SSH we will need to update the Raspberry Pi and its packages, do this by entering:
    sudo apt-get update
    sudo apt-get upgrade
    
  2. Now we need to open up the Raspi Config Tool to change a few settings.
    sudo raspi-config
    
  3. In here we will need to change a few settings.
    • Change Locale to en_US.UTF8 in internationalisation options -> change local.
    • Change memory split to 16m in Advanced options -> Memory split.
    • Change overclock to medium.
  4. Add the www-data user to the www-data group.
    sudo usermod -a -G www-data www-data
    
  5. Now we need to install all the required 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-curl php5-gd php5-fpm memcached php5-memcache varnish
  1. Now we need to create an SSL certificate you can do this by running the following command:
sudo openssl req $@ -new -x509 -days 730 -nodes -out /etc/nginx/cert.pem -keyout /etc/nginx/cert.key

Simply just enter the relevant data for each of the questions it asks you.

  1. Now we need to chmod the two cert files we just generated.
sudo chmod 600 /etc/nginx/cert.pem
sudo chmod 600 /etc/nginx/cert.key
  1. Let’s clear the server config file since we will be copying and pasting our own version in it.
sudo sh -c "echo '' > /etc/nginx/sites-available/default"
  1. Now let’s configure the web server configuration so that it runs Owncloud correctly.
sudo nano /etc/nginx/sites-available/default
  1. Now simply copy and paste the following code into the file. Replace my IP (192.168.1.116) at server_name (There is 2 of them) with your Raspberry Pi’s IP.
upstream php-handler {
    server 127.0.0.1:9000;
    #server unix:/var/run/php5-fpm.sock;
}
server {
    listen 80;
    server_name 192.168.1.116;
    return 301 https://$server_name$request_uri;  # enforce https
}

server {
    listen 443 ssl;
    server_name 192.168.1.116;
    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 1000M; # 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;
   }
}

  1. Now simply save and exit.
  2. Now that is done there is a few more configurations we will need to update, first open up the PHP config file by entering.
    sudo nano /etc/php5/fpm/php.ini
    
  3. In this file we want to find and update the following lines. (Ctrl + w allows you to search)
    upload_max_filezise = 2000M
    
    post_max_size = 2000M
    
  4. Once done save and exit. Now we need to edit the conf file by entering the following:
    sudo nano /etc/php5/fpm/pool.d/www.conf
    
  5. Update the listen line to the following:
    listen = 127.0.0.1:9000
    
  6. Once done save and then exit. Now we ne also need to edit the dphys-swapfile. To do this open up the file by entering:
    sudo nano /etc/dphys-swapfile
    
  7. Now update the conf_swapsize line to the following:
    CONF_SWAPSIZE = 512
    
  8. Restart the Pi by entering:
    sudo reboot
    
  9. Once the Pi has restarted you will need to install Owncloud onto the Raspberry Pi. Do this by entering the following commands:
sudo mkdir -p /var/www/owncloud
sudo wget http://bit.ly/1sCWFsY
sudo tar xvf owncloud-8.1.1.tar.bz2
sudo mv owncloud/ /var/www/
sudo chown -R www-data:www-data /var/www
rm -rf owncloud owncloud-8.1.1.tar.bz2

  1. We also need to make some changes to .htaccess file and the .user.ini file over in the Owncloud folder. Enter the following command to change directory and open up the .htaccess file.
    cd /var/www/owncloud
    sudo nano .htaccess
    
  2. In here set the following values to 2000M
    php_value_upload_max_filesize 2000M
    
    php_value_post_max_size 2000M
    
    php_value_memory_limit 2000M
    
  3. Save and exit, Open up the .user.ini file
sudo nano .user.ini
  1. In here update the following values so they are 2000M:
    upload_max_filesize=2000M
    
    post_max_size=2000M
    
    memory_limit=2000M
    
  2. Now that is done we should be able to connect to Owncloud at your PI’s IP address.

Before you set up the admin account you might want to mount an external drive so you have lots of disk space for your Raspberry Pi Owncloud . Simply follow the instructions in the next section.

Mounting & Setting up a drive

Setting up an external drive whilst should be relatively straight forward but sometimes things don’t work as perfectly as they should.

These instructions are for mounting and allowing Owncloud to store files onto an external hard drive.

  1. Firstly if you have a NTFS drive we will need to install a NFTS package by entering the following:
    sudo apt-get install ntfs-3g
    
  2. Now let’s make a directory we can mount to.
    sudo mkdir /media/ownclouddrive
    
  3. Now we need to get the gid, uid and the uuid as we will need to use them soon. Enter the following command for the gid:
    id -g www-data
    
  4. Now for the uid enter the following command:
    id -u www-data
    
  5. Also if we get the UUID of the hard drive the Pi will remember this drive even if you plug it into a different USB port.
    ls -l /dev/disk/by-uuid
    

    UUID Hard Drive
    Copy the blue letters and numbers of the last entry (Should have something like -> ../../sda1 at the end of it).

  6. Now let’s add your drive into the fstab file so it is booted with the correct permissions.
    sudo nano /etc/fstab
    
  7. Now add the following line to the bottom of the file, updating uid, guid and the UUID with the values we got above. (The following should all be on a single line)
    UUID=DC72-0315 /media/ownclouddrive auto nofail,uid=33,gid=33,umask=0027,dmask=0027,noatime 0 0
    
  8. Reboot the Raspberry Pi and the drives should be mounted. If they are mounted we’re all good to go.

Basic First Setup

I will briefly go through the basics of setting up Owncloud Raspberry Pi here. If you want more information I highly recommend checkout out the manuals on their website, you can find them here.

  1. In your browser enter your Pi’s IP address in my case it is 192.168.1.116.
  2. Once you go to the IP you’re like to get a certificate error, simply add this to your exception list as it will be safe to proceed.
  3. When you first open up ownCloud you should be presented with a simple setup screen and no errors.
  4. Enter your desired username and password.
  5. Click on storage & database and enter your external drive /media/ownclouddrive (Skip this step if you didn’t setup an external drive).
  6. Click finish setup.

Owncloud Signup

Port Forwarding & External Access

If you want to have access to your cloud drive outside your local network, then you will need to setup port forwarding and make a few changes to our config files.

Firstly, we need to go back into the default file and change the server_name values (There is 2 of them). Update these to your external IP address. You can get your IP at what is my IP.

If you have a dynamic IP you may want to setup a dynamic DNS and use that as your address. You can find information on this in my guide to port forwarding.

Enter the following to bring up our default server file:

sudo nano /etc/nginx/sites-available/default

Once you have updated the IP’s in the server file you will need to add the external IP to your trusted IP list and make sure owncloud doesn’t overwrite it. To do this open up the Owncloud config file and enter:

sudo nano /var/www/owncloud/config/config.php

In here add a new item to the trusted domains array (This will be your external IP address). Your new entry should look something like this (x are just placeholders).

1 => 'xxx.xxx.xxx.xxx',

Finally update the URL of the overwrite.cli.url line to your IP Address. It should look something like this.

'overwrite.cli.url' => 'https://xxx.xxx.xxx.xxx',

Below is an example of the completed config.txt file.
External IP Change Example

Once done restart the nginx service by entering the following:

sudo service nginx restart

Be sure to check out my guide on port forwarding and use the following port 443 for internal and I recommended a random port for the external port. Make sure when setting up the external port that it isn’t already reserved by a certain program.

When connecting to the owncloud server externally you will need to make sure you use https otherwise you will get a invalid request in your browser.

Setting up port forwarding is super easy to do and allows you to have access to your personal cloud on the go. Also after you have done this you can still connect via your local IP as well.

I hope this tutorial has helped you make your very own Raspberry Pi OwnCloud. If you have any troubles, want to leave feedback or if I have missed anything feel free to drop us a comment below.

 

 

Share This:

View more at: http://bit.ly/1XReQFr

About Author

Advertisement

Post a Comment

 
Top