Install OwnCloud 9 on Raspberry Pi 3 with Raspbian Jessie Installed

Our goal in this long journey of installing ownCloud 9 on the Raspberry pi is not just installing ownCloud but also mounting an external drive for lager capacity of data storage and to be able to access it from anywhere in the world.

This tutorial assumes that you have a fully functional Raspberry pi-2 or 3 with Raspbian installed and a 8 GB Micro SD card Minimum!. If you haven’t installed Raspbian then check out my guide on how to install Raspbian via NOOBS.

There are many ways to install ownCloud onto a Raspberry Pi. This particular tutorial I’ll be downloading and installing the following software / packages we will be using to setup ownCloud 9:

• ownCloud 9.0.2
• Nginx
• OpenSSL
• php 5

If you don’t have a Raspberry PI I would personally recommend buying the Raspberry pi-3 kit with a 32 GB Micro SD card so that you don’t have to mount an external drive. unless you want to store more than 32GB of data.

Video Tutorial:


Setting up Raspberry Pi for Owncloud Server

1. Turn on the Raspberry Pi. From the terminal or SSH enter the following command:

sudo raspi-config

The following changes needs to be made in the Raspberry Pi configuration

a. Expand the root filesystem to have enough space for the cloud
Select “Expand Filesystem

b. Change user password
For Security when accessing form the WAN

c. Change locale to en_US.UTF8
Select “Internationalisation Options

d. Memory split, allocate 16M to video graphics
Select “Advanced Options” –> “Memory Split

e. Overclock to Modest or Medium
Select “Overclock

2. Update the Raspberry Pi and its packages:

sudo apt-get update
sudo apt-get upgrade

3. Create and add the www-data user to the www-data group:

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

4. Install 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

5. Create an SSL certificates for 2 years:

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

6. chmod the two cert files we just generated:

sudo chmod 600 /etc/nginx/cert.pem
sudo chmod 600 /etc/nginx/cert.key

7. let’s move to backup nginx default cofiguration file:

sudo mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default_old

8. create a new nginx default cofiguration file:

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

9. Now  copy and paste the code underneath into the file. Replace “IPaddress” next to “server_name” with your Raspberry Pi’s IP (There is 2 of them).

upstream php-handler {
    #server unix:/var/run/php5-fpm.sock;
server {
    listen 80;
    server_name IPaddress;
    return 301 https://$server_name$request_uri; # enforce https
server {
    listen 443 ssl;
    server_name IPaddress;
    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;

10. Now save and exit by pressing Ctrl plus X, Y for yes and enter key on your keyboard.

11. Configure max upload limit in php:

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

Use Ctrl+w to search for the lines below and update:

upload_max_filesize = 2000M
post_max_size = 2000M

12. Update PHP listen line:

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

Change the following line from:

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

13. Update the conf_swapsize line:

sudo nano /etc/dphys-swapfile

Change the following line from:


14. Restart the pi:

sudo reboot

Installing ownCloud 10:

15. Once the Pi has fully restarted we are ready to install ownCloud version10.0.0.3 by entering the following commands:

sudo mkdir -p /var/www/owncloud
sudo wget
sudo tar xvf owncloud-10.0.3.tar.bz2
sudo mv owncloud/ /var/www/
sudo chown -R www-data:www-data /var/www
rm -rf owncloud owncloud-10.0.3.tar.bz2

16. If you are NOT mounting an external hard drive to the raspberry pi then you are ready to log into your ownCloud Server by entering the RPI IP address into the address bar.

If  you’re mounting an external hard drive so you’d have lots of disk space for your Raspberry Pi ownCloud server, you would need to mount the hard drive before you log into your ownCloud Server. Simply follow the instructions below.

Mounting and Setting up a drive

These instructions are for mounting an NTFS formatted hard drive and allowing ownCloud to store files onto it.

1. Having an NTFS drive we will need to install a NFTS package by entering the following:

sudo apt-get install ntfs-3g

2. Make a directory we can mount to:

sudo mkdir /media/ownclouddrive

3. Create and add the www-data user to the www-data group:

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

4. Make the user www-data owner of the mounted drive and make its permissions read, write and execute:

sudo chown -R www-data:www-data /media/ownclouddrive
sudo chmod -R 775 /media/ownclouddrive

5. Now we need to get the gid, uid and the uuid as we will need to use them so the pi will remember it even if we plug it into a different USB port. Enter the following command for the gid:

id -g www-data

6. Now to get the uid enter the following command:

id -u www-data

7. Also we meed to get the UUID of the attached external hard drive so the Pi can remember this drive even if you plug it into a different USB port.

ls -l /dev/disk/by-uuid

8. Then copy the light blue letters and numbers of the sda1 entry usually located on the bottom. Should look something like (numbers&letters -> ../../sda1). See picture below:


9. Now add your drive into the fstab file so it’ll boot with the proper permissions.

sudo nano /etc/fstab

10. Add the following line to the bottom of the file, updating uid, guid and the UUID with the values we got above. (It should all be a single line)

UUID=F6941E59941E1D25 /media/ownclouddrive auto nofail,uid=33,gid=33,umask=0027,dmask=0027,noatime 0 0


11. Reboot the Raspberry Pi:

sudo reboot

12. Now the drives should automatically be mounted. If mounted we’re all good to go. To check it enter:

sudo ls /media/ownclouddrive

Personal Cloud Storage

If there are files inside the drive you should be able to see them here. If it’s an empty drive you might not see anything so don’t be surprise if nothing shows up.

If you want to be absolutely positive that the drive is properly mounted, unplug the drive from the RPI plug it onto a PC since the drive is formatted “NTFS” it should be easily detected by the PC, open it, create an txt file name it test, then eject it and plug it back to the RPI and run the following command:

sudo ls /media/ownclouddrive

The txt file you created should be there.

Basic First Access Setup

1. Open your browser and enter the IP address provided, in my case is you’ll be directed to your ownCloud storage server.

2. Because we installed SSL for more security you might get a certificate error, simply add the certificate to your exception list to proceed.

3. You should be presented with a simple setup screen, Here enter a username and password to create an admin account.

4. Click on Storage & database dropdown and enter your external hard drive: /media/ownclouddrive (Skip this if you didn’t setup an external drive).

5. Click Finish setup.


Done! !! all is left is to configure your devices to access your ownCloud storage.

Port Forward for External Access

Log into your router and get the WAN IP address:


Or Google what is my IP address?


Now we need to add the WAN IP to your trusted IP list and not to be overwritten by ownCloud. To do this open the Owncloud config file, enter:

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


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

Here add the WAN IP (External IP address) you just got from the router or Google to the trusted domains array. Your new entry should look something like this:

1 => '',

X are just placeholders. Replace the X’s with the WAN IP Address.

Now update the URL of the overwrite.cli.url line with your WAN IP Address. It should look something like this:

'overwrite.cli.url' => '',

Here is an example of the completed config.txt file.


Once done save and restart the nginx service:

sudo service nginx restart

Now log into your router and navigate to the port forward section.


Now port forward SSL port 443 to the Raspberry pi internal IP (LAN IP)  address and save settings.


Now your RPI ownCloud is ready to be accessed externally (WAN) and from your devices just download the ownCloud App and enter: “https:// WAN IP Address” on the address bar or devices. below is an example:


You May Also Like

About the Author: Miguel

I started this tech blog back in 2011 as a place to write down processes I took to fix my client systems and network. Now I write some tips and tricks to help others with the tech issues that one might encounter.


  1. Excellent, thank you. I’m not sure but i think we need to do “sudo chown -R www-data:www-data /media/ownclouddrive” after the drive is mounted.
    I installed on the NanoPi M2 from Friendly Arm 🙂

    1. I’m glad it worked. Thanks for the comment. Ill keep that in mind in case someone else have the same issue.

      1. Hi Miguel, I found your site very interesting. Do you have a discussion on how to install a proper version of moodle on raspberry pi 3 please. It would be very much appreciated.

  2. Hi,

    First one, great tutorial.
    Second one, I hope you can help me. I have been searching but I haven’t found anything. In my owncloud I have two issues:
    1.- How to enable Strict-Transport-Security?
    2.- How to config cache memory?

    Thank you so much,

      1. For some reason, I received the message saying the site was unreachable when I entered the IP address of the PI. Any insights?

          1. They step where I enter the IP address of the PI into a web browser of another computer.

  3. Hi Miguel thanks for the tutorial, but In my owncloud I have an error “file not found” when go to localhost/owncloud or IP_XXXXX/owncloud, can you help me?
    Thanks you!

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

    im sorry i want to ask, i cant accecss i install using owncloud 10. can you help me ? are the problem is from cert.key ?

  5. I followed this step by step but after following it through to “Basic First Access Setup” I run into issues as htts into Raspberry Pi private IP address gives no owncloud page. If I try to run the occ command it says it is not installed but followed each command in the block:

    sudo mkdir -p /var/www/owncloud
    sudo wget
    sudo tar xvf owncloud-9.0.2.tar.bz2
    sudo mv owncloud/ /var/www/
    sudo chown -R www-data:www-data /var/www
    rm -rf owncloud owncloud-9.0.2.tar.bz2

    Don’t know where this has blown a fuse. Any help gratefully recieved.

  6. Hi Miguel thank you for the tutorial. I followed your process for attaching an external hard drive but when I log into my cloud, I cannot see the contents of the hard drive. I only see the generic example docs, pics, etc that come with the software. How do I fix this issue? I appreciate your help.

  7. Hi Miguel! Thanks for the awesome tutorial, it works fine for me at first. However, I encounter this problem after safely eject and reinsert my HDD

    “Error mounting system-managed device /dev/sda1: Command-line `mount “/media/ownclouddrive”‘ exited with non-zero exit status 18: Failed to write lock ‘/dev/sda1’ ” which denies my permission to access external HDD in owncloud.

    I hope you can help me resolve this issue! Thank you!

    1. 1. reboot with the external drive pluged in to the RPI
      2. run the ls -l /dev/disk/by-uuid make a note of the UUID
      3. then run sudo nano /etc/fstab and make sure that the UUID is the same.
      4. reboot

  8. Hi Miguel I created my admin account to early in the process and didn’t set the storage and database. How do I change the path from the default “/var/www/owncloud/data” to “/media/owncloud” for the external hard drive?

    1. run this command in the terminal:
      sudo nano /var/www/html/owncloud/config/config.php
      sudo nano /var/www/owncloud/config/config.php
      and change the datadirectory to /media/owncloud

      then move your owncloud data:
      sudo mv /var/www/html/owncloud/data /media/owncloud
      sudo mv /var/www/owncloud/data /media/owncloud
      then restart
      sudo service apache2 restart
      sudo apache2 restart

  9. I got till the last step
    but in the owncloud setup. Owncloud is asking for the mySQL/mariadb username and login. where did i go wrong and how to correct it.

Leave a Reply

Your email address will not be published. Required fields are marked *