Social Icons

Install OwnCloud 8 with Nginx and MySql on Raspberry Pi

This article has been long due from our side since OwnCloud 8 has been released, the product is pretty stable and popular now with the latest stable release of version 8.1.1

Like previous iterations, keeping in mind the small footprint and power of Raspberry Pi we would be using following components:
  • Nginx (as Webserver instead of Apache, as it would be faster)
  • MySql
  • Php 5
So without much ado, let get straight into Business...

Step 1.
Update the repositories
sudo apt-get update

Step 2.
Install MySql
sudo apt-get install mysql-server

Enter a password for root account when prompted, and do remember it :)














Step 3.
Let's now configure the mysql so that it runs better on our tiny resource tight Raspberry Pi
Backup existing config
sudo mv /etc/mysql/my.cnf /etc/mysql/my.cnf.bak

Use a suitable config for Raspberry Pi
sudo cp /usr/share/doc/mysql-server-5.5/examples/my-small.cnf /etc/mysql/my.cnf

Edit the config file
sudo nano /etc/mysql/my.cnf

Find the [mysqld] section of the file and place the following line in it:
query_cache_size = 8M

Step 4.
Now we will connect to the database and created required db objects and users
mysql -u root -p

Execute the following at MySql prompt (change the fields in red as per your setup)
CREATE DATABASE owncloud;
CREATE USER techjawab@localhost IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON owncloud.* TO techjawab@localhost;
FLUSH PRIVILEGES;
exit;


Step 5.
Install Php5 and related libraries
sudo apt-get install php5-mysql openssl ssl-cert php5-cli php5-common php5-cgi php-pear php-apc curl libapr1 libtool php5-curl libcurl4-openssl-dev php-xml-parser php5-dev php5-gd memcached php5-memcache

Step 6.
Install Nginx
sudo apt-get install php5-fpm nginx

Step 7.
Install and configure OwnCloud
Create directories required for owncloud
sudo mkdir -p /var/www/owncloud
cd /var/www/


Download OwnCloud and set permissions
sudo wget https://download.owncloud.org/community/owncloud-8.1.1.tar.bz2
sudo tar -xvf owncloud-8.1.1.tar.bz2
sudo chown -R www-data:www-data /var/www


Create SSL certificates for https connection
sudo mkdir -p /etc/nginx/ssl
sudo openssl req -x509 -nodes -days 36500 -newkey rsa:2048 -keyout /etc/nginx/ssl/owncloud.key -out /etc/nginx/ssl/owncloud.crt

Configure owncloud
Edit the below file and copy - paste the config given below
Note:  Remember to edit your domain name or ip under "server_name" field both for http and https
sudo nano /etc/nginx/sites-available/owncloud



Enabling owncloud settings
sudo ln -s /etc/nginx/sites-available/owncloud /etc/nginx/sites-enabled/owncloud
sudo unlink /etc/nginx/sites-enabled/default


Configure Php FastCGI Process Manager
sudo nano /etc/php5/fpm/php.ini


Set the following values accordingly in the config file, change value for upload directory according to your setup

default_charset = "UTF-8"
upload_max_filesize = 10G
post_max_size = 10G
upload_tmp_dir = /mnt/usbstorage/owncloud/tmp
max_input_time = 360000
#The maximum time in seconds a script is allowed to parse input data.
max_execution_time = 360000
memory_limit = 512M
extension=memcached.so
extension=memcache.so


Restart the services
sudo service nginx restart
sudo service php5-fpm restart


Create directories for owncloud on your mounted external storage
sudo mkdir -p /media/NASDRIVE/owncloud
sudo chown -R www-data:www-data /media/NASDRIVE/owncloud


sudo mkdir -p /media/NASDRIVE/owncloud/tmp
sudo chown -R www-data:www-data /media/NASDRIVE/owncloud/tmp


Step 8.
Open Browser and browse to your domain name or ip address


You would need to setup the following:
  • setup admin username / password
  • Provide the owncloud storage path created above
  • Provide database name, username and password created in step 4, and click "Finish setup"













Viola, you have your "own"cloud up and running now...



7 comments:

  1. Nice work! Thank you! After successful install I found some warnings in "Admin" module. The issue with "The Strict-Transport-Security" HTTP header is not configured to least "15768000" I solved adding "add_header Strict-Transport-Security max-age=31536000;" in /etc/nginx/nginx.conf.
    Now I try to get rid of "No memory cache has been configured." warning. I added in /etc/php5/fpm/php.ini at "Dynamic Extensions" section:
    extension=memcached.so
    extension=memcache.so
    But the warning is still there...

    ReplyDelete
  2. not working for me!
    Step 8: can't access ip... 403 forbidden.
    Configured exactly like you (except ip-address and NAS)

    any ideas?

    ReplyDelete
    Replies
    1. Add /owncloud at the end of your domain name or ip address

      Delete
  3. Thanks for the guide, it was really useful. I now have a working Owncloud server running on a Raspberry Pi 3.

    A couple of pointers to make it just that little bit less stressful:

    1) In /etc/nginx/sites-available/owncloud
    #Path to the root of your installation should be:
    root /var/www/owncloud;
    and not
    root /var/www;

    Otherwise you'll get a '403 Forbidden' error in your browser.

    2) I mounted a 128GB USB drive, formatted as FAT32, with the following line added to /etc/fstab:

    UUID=1234-5678 /media/USB128 auto nofail,uid=33,gid=33,umask=0027,dmask=0027,noatime 0 0

    (After, of course, creating the USB directory in media, e.g.
    sudo mkdir /media/USB

    The Owncloud configuration wizard complains if your data directory is too wide open so I've used umask and dmask to limit r+w access to user and group 33 (www-data). Obviously the UUID has to be whatever it is in your configuration, Use sudo blkid to find it.

    Once you've successfully mounted your external storage, create an owncloud directory and within this create a tmp directory:

    eg:
    sudo mkdir /media/USB/owncloud
    sudo mkdir /media/USB/owncloud/tmp

    3) In /etc/php5/fpm/php.ini where you have
    upload_tmp_dir = /mnt/usbstorage/owncloud/tmp
    Change this to:
    upload tmp dir = /media/USB/owncloud/tmp

    I don't know what this is for but if I watch the tmp directory while owncloud is syncing my desktop (i.e. while it is uploading files from my desktop to the server) I can see files appearing and then disappearing. I'm guessing it's meant to speed things up a bit.

    4) When you're filling in the initial screen - the Owncloud configuration wizard - make sure to set the data directory to:

    /media/USB/owncloud

    (If that's where you've mounted your external storage.)

    5) The database username is whatyoumadeit and not whatyoumadeit@localhost.

    Hope these help a bit!

    ReplyDelete
  4. pi@raspberrypi:~ $ systemctl status nginx.service
    ● nginx.service - A high performance web server and a reverse proxy server
    Loaded: loaded (/lib/systemd/system/nginx.service; enabled)
    Active: failed (Result: exit-code) since Thu 2016-06-09 20:59:59 IST; 1min 4s ago
    Process: 2253 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
    pi@raspberrypi:~ $

    please how to solve this issue

    ReplyDelete
  5. Hi Team,

    I solved the above problem, But I am getting below error.
    403 Forbidden
    nginx/1.6.2

    not able to see anything here

    ReplyDelete
  6. Hi Team,

    Thank you so much for your help. At last I able to solve the problem.

    I have added these two things here.

    Step 1) got to the folder /var/www/owncloud
    sudo vi .htaccess
    add below lines in last

    order allow,deny
    allow from all


    order allow,deny
    allow from all

    step 2)
    I was typed just IP address of my Raspberry pi. But I learnt, I should type below full address.

    https://192.168.1.33/owncloud/index.php

    ReplyDelete