How to install ownCloud on a Raspberry Pi

In this posting, we are going to install a personal Cloud package, called “ownCloud”, on a Raspberry Pi.

Preparation of the Raspberry Pi

  • Follow the instructions at How to install the Raspbian OS on a Raspberry Pi.
  • Change the hostname of your Raspberry Pi to something more meaningful by logging on to the device as user “pi” and issuing the command:

    sudo raspi-config

  • Select “Advanced Options” and set the following:
    • Hostname = pi-owncloud (or whatever you want to call it).
  • Select Finish
  • Reboot the Raspberry Pi

Install PHP, SqlLite, the Nginx web server, and other support packages

These instructions have been modified from thos originally found at http://www.techjawab.com/2013/09/how-to-setup-your-own-cloud-on.html.

  • Create a user for the Nginx web server with the command:

    sudo groupadd www-data ; sudo usermod -a -G www-data www-data

  • Install the necessary packages with the command:

    sudo apt-get install nginx openssl ssl-cert php5-cli php5-sqlite php5-gd php5-curl 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

  • Create your SSL certificates (which will last for 2 years) with the commands:


    sudo openssl req $@ -new -x509 -days 730 -nodes -out /etc/nginx/cert.pem -keyout /etc/nginx/cert.key
    sudo chmod 600 /etc/nginx/cert.pem ; sudo chmod 600 /etc/nginx/cert.key

Configure the Nginx web server

  • Open the configuration file for editing:

    sudo vi /etc/nginx/nginx.conf

  • Because the Raspberyy Pi only has 2 cores, change


    worker_processes 4;
    …to:
    worker_processes 2;

  • Change the top of the http section to:


    http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    # keepalive_timeout 65;
    types_hash_max_size 2048;
    server_tokens off;

    client_header_timeout 10;
    client_body_timeout 10;
    keepalive_timeout 10 10;
    send_timeout 10;

  • Change the Gzip section from:


    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    …to:
    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    gzip_min_length 1100;
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

  • Now do the following:


    sudo vi /etc/php5/fpm/pool.d/www.conf
    …and uncomment the following two lines::
    listen.owner = www-data
    listen.group = www-data

  • Enter the following command:

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

  • …and replace the entire content of the file with the code below (taken from http://doc.owncloud.org/server/5.0/admin_manual/installation/installation_others.html#nginx-configuration). Note: You’ll have to replace two occurrences of 192.168.XXX.XXX with the local IP address of your Raspberry Pi.


    server {
    listen 80;
    server_name 192.168.XXX.XXX;
    return 301 https://$server_name$request_uri; # enforce https
    }

    server {
    listen 443 ssl;
    server_name 192.168.XXX.XXX;

    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 ~ ^/(data|config|\.ht|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)(/.*)?$ {
    try_files $1 = 404;

    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$1;
    fastcgi_param PATH_INFO $2;
    fastcgi_param HTTPS on;
    fastcgi_pass 127.0.0.1:9000;
    # Or use unix-socket with 'fastcgi_pass unix:/var/run/php5-fpm.sock;'
    }

    # 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;
    }

    }

Configure the maximum upload limit for php

  • Enter the following command to edit the file:

    sudo vi /etc/php5/fpm/php.ini

  • …and set:


    upload_max_filesize = 1000M
    post_max_size = 1000M

  • At the end of the file, add ┬áthe following:


    upload_tmp_dir = /srv/http/owncloud/data
    extension = apc.so
    apc.enabled = 1
    apc.include_once_override = 0
    apc.shm_size = 256

Configure PHP

  • Enter the following command:

    sudo vi /etc/php5/fpm/pool.d/www.conf

  • Change the following line from:


    listen = /var/run/php5-fpm.sock

    …to


    listen = 127.0.0.1:9000

Increase the size of the swap file

  • Enter the following command:


    sudo vi /etc/dphys-swapfile

    …and change the following line from:


    CONF_SWAPSIZE=100

    …to :


    CONF_SWAPSIZE=512

  • Restart the web server and Php with the commands:


    sudo /etc/init.d/php5-fpm restart
    sudo /etc/init.d/nginx restart

Install ownCloud

Enter the following commands to install ownCloud on your Raspberry Pi (by the time you read, this there may be a newer version of ownCloud available).

  • To create a folder for ownCloud with the relevant rights, enter the following commands:


    sudo mkdir -p /var/www/owncloud
    sudo wget http://download.owncloud.org/community/owncloud-6.0.2.tar.bz2
    sudo tar xvf owncloud-6.0.2.tar.bz2
    sudo mv owncloud/ /var/www/
    sudo chown -R www-data:www-data /var/www
    rm -rf owncloud owncloud-6.0.2.tar.bz2

Finally:

  • Go to https://192.168.XXX.XXX/ (replace the address with your own IP address) and create an Admin account.
  • You should now have a working copy of ownCloud on your Raspberry Pi, and you can follow the manual at http://owncloud.org/ to figure out how it works.
Advertisements