Install OwnCloud on your Raspberry Pi

Owncloud Logo

OwnCloud is a free (libre), open source equivalent to DropBox.

As well as the program you install on your server, it has free desktop sync clients for Linux, Windows and Mac, and apps for Android and iOS.

I’m just going to cover the server side of things for your Pi in this tutorial, because the desktop client can be found in the Ubuntu repos, and the app is on the Play Store. If you want the Android app free of charge, then install it via F-Droid.

First, install Apache 2 and some other bits.

These are all the bits you need to install before you can run OwnCloud.

sudo apt-get install apache2 php5 php5-gd php-xml-parser php5-intl
sudo apt-get install php5-sqlite php5-mysql smbclient curl libcurl3 php5-curl

Next, Download and Install OwnCloud

If you visit the Owncloud installation page here, you will find the installation file.

Choose “Tar or Zip File” under the server heading.

OwnCloud intsallation download page

Now copy the link address of .tar.bz2 file (you can do this by right clicking and choosing “Copy Link Address” in Chrome or Chromium). At the time of writing, this address is, but it will change when a new version comes out, so it’s worth checking.

Save the address of the UNIX .tar.bz2 file (right click, copy link address in Chrome)

Save the address of the UNIX .tar.bz2 file (right click, copy link address in Chrome). Now, open a secure shell (SSH) into your Pi, and download the file:


The zip file will be downloaded to your home directory (unless you were in some other directory before you ran that command, in which case it will be in there). Now extract the .tar file:

tar -xjf owncloud-5.0.12.tar.bz2

You will now have a sub-directory in your home directory called owncloud. Copy it to Apache’s data directory:

cp -r owncloud /var/www/

This will copy all your owncloud stuff into a directory at /var/www/owncloud, meaning that your owncloud website will be located at

Optional: Move OwnCloud to the Root Apache2 Directory

If you would like owncloud to be on the root of your domain (i.e. takes you straight to owncloud) then you can move the contents of /var/www/owncloud up a directory into /var/www/ with the following command:

cd /var/www/
sudo find owncloud -maxdepth 1 -mindepth 1 -exec mv {} . \;
sudo rmdir owncloud

I got that handy tip from this website, check it out for a great explanation.

A Few Final Touches

Now, make sure that Apache owns all of those files you just added:

sudo chown -R www-data:www-data /var/www/

Now open your Apache virtual host file and change it to enable .htaccess files for OwnCloud (this is necessary so that OwnCloud can do things like override the global maximum file size for uploads):

sudo nano /etc/apache2/sites-enabled/000-default

Change AllowOverride None to AllowOverride All in the Directory /var/www/ section of the file.

Now check if an .htaccess file for OwnCloud exists. If it doesn’t, create it:

cd /var/www/ #use /var/www/owncloud if you didn't move it to /var/www/
ls -al
#look for .htaccess. If it exists, skip the next two lines
sudo touch .htaccess
sudo chown www-data:www-data .htaccess

Now run the following two commands to enable some apache modules, and restart apache2:

sudo a2enmod rewrite
sudo a2enmod headers
sudo service apache2 restart

Port Forwarding and DNS

If you want to access your ownCloud installation from outside your LAN, you'll need to forward ports 80 and 443 (for HTTP and HTTPS) to the Pi from your router.

If you haven't done this already, you may want to use my tutorials to set up a DNS A record to map your domain name to your public IP address, and make use of ddclient to update your DNS records when they change if you have a dynamic IP address.


Test your installation, by visiting your server’s URL. Either use if you didn’t move owncloud to Apache’s root directory, or if you did.

You should be greeted with an installation wizard.

Owncloud database drivers error

If you get an error about database drivers, then try installing php5-mysql again – for some reason, it didn’t install properly first time for me, although no errors were shown:

sudo apt-get install php5-mysql
sudo reboot

You should no longer see the error if you visit the page again.

Database Username and Password

The OwnCloud installation wizard will ask you for a database username and password.

If you haven’t set up any other databases on this server before (and therefore don’t have a root database user and password) then you will have to create a root database username and password before you can continue. If you are already using software that uses databases (like WordPress) then you probably already have a database root username and password, and can skip this step.

Install mysql server and client:

sudo apt-get update
sudo apt-get install mysql-server mysql-client

The package installation will bring up a configuration wizard. Enter the username you’d like to use, and a password. Write these down, you’ll need them later.

Now you can complete the installation. Go back to your browser with the OwnCloud setup wizard, and choose a username and password for your OwnCloud user account. You also need to enter the database root username and password, and choose a name for the OwnCloud database (“owncloud” will do). The database location is localhost.

Some extras

1) Cut Page Loading Times with a PHP Cache

PHP is a server side scripting language. When you request a page on the server, the server has to compile the page from the PHP source.

Because your Pi is such a low powered machine, this can be really slow.

Luckily, there’s a PHP cache you can use that will store a pre-compiled copy of pages in your RAM after they have been visited already. This makes a MASSIVE difference – before installing the cache, it took 21 seconds to load the index page, afterwards a mere 7-8 seconds.

Install it by using this command:

sudo apt-get install php-apc

Now restart the Apache web server using:

sudo service apache2 restart

The first time you visit a page may be slow, but if you navigate away and then come back to it you should notice a significant improvement.

Thanks to Steve Riley at Kubuntuforums for this tip.

2) Put all your data on an external hard drive

If you have moved your Pi’s root filesystem to a USB flash drive then you may have enough storage to use OwnCloud as it is.

However, one of the main advantages of using OwnCloud instead of Dropbox is that you can easily plug in as many hard drives as you like and wave goodbye to that 5GB storage limit.

I attached a self-powered 500GB hard drive to mine, and it works beautifully. Remember, the Pi doesn’t have enough power to run a passport drive without an external hub to provide power.

Before we start, format your hard drive with a journalling filesystem such as ext3 or ext4.

First, make the directory ready to mount your drive:

sudo mkdir /media/owncloud

Plug in your drive to your Pi, and type:

sudo blkid

Make a note of the output for the device you want to mount. Here’s an example (it’s for one of my laptop’s partitions, hence /dev/sda6, yours will be a whole drive, e.g. /dev/sdX)

/dev/sda6: LABEL="Data" UUID="f052e620-9e88-4b19-9b9a-d6dce4d6603b" TYPE="ext4"

Now edit the file /etc/fstab, which controls how and where drives are mounted at boot.

sudo nano /etc/fstab

Edit the file so it looks something like this, but replace my UUID with yours and update the filesystem type from ext4 to whatever you are using if necessary:

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
UUID="96f64567-c459-4d3d-9f52-e6aabee544d2"     /media/owncloud         ext4    defaults    0       2
# a swapfile is not a swap partition, so no using swapon|off from here on, use  dphys-swapfile swap[on|off]  for that

Now reboot the Pi and check your drive is mounted properly:

cd /media/owncloud
ls -al

Stop Apache2:

sudo service apache2 stop

Now we need to move Owncloud’s data directory, and create some symbolic links so that the rest of Owncloud still knows where to look for data.

Where you’re moving stuff from depends on whether or not you moved owncloud to Apache’s root (/var/www). If you did move it, then owncloud is currently installed at /var/www; if you didn’t move it then it’s in /var/www/owncloud.

I’m going to assume that you did move Owncloud. If you didn’t, then you need to insert /owncloud after /var/www in each of these steps.

Move /var/www/data to /media/owncloud:

sudo mv /var/www/data /media/owncloud/data

Create a symbolic link to the new owncloud directory.

sudo ln -s /media/owncloud/data /var/www/data

Now do the same for the config folder:

sudo mv /var/www/config /media/owncloud/config
sudo ln -s /media/owncloud/config /var/www/config

Now check that the ownership of the moved files is Apache (www-data):

sudo chown -R www-data:www-data /media/owncloud

Now start Apache2 again:

sudo service apache2 start

Any data you now upload should go in your external hard drive.

I owe thanks to Steve Riley (again!) at OwnCloud forums for this one.

3) Force SSL (https) Connection

You can force your users to connect to OwnCloud using an HTTPS connection.

Simply change the virtual hosts file for apache2 to enable .htaccess as before: open /etc/apache2/sites-available/default-ssl and change AllowOverride None to AllowOverride All under the Directory /var/www/. Make sure you have the line SSLEngine on, and your SSLCertificateFile and SSLCertificateKeyFile point to the certificates you’d like to use.

Now enable the Apache SSL module:

sudo a2enmod ssl

Enable the SSL site:

sudo a2ensite default-ssl

Reload Apache:

sudo service apache2 reload

Now visit if you didn’t move apache to your root, or if you moved owncloud to your root directory.

Using the drop-down menu, navigate to admin –> admin, and under the Security header, tick the Enforce HTTPS box.

Check the Enforce HTTPS box

Note that you will only be able to do this if you are connected with https (otherwise you’d lock yourself out!)

All done. Now all your communications between the client machines and your server will be encrypted. If you try to visit the http version of OwnCloud, you will be redirected to https.

If you don't already have a SSL certificate, you may want to generate your own and get it signed by CAcert for free.

Hope you found that useful. If there’s anything else you’d like to know, leave a comment!



Hi Sam,

I appreciate the feedback. I will dedicate another machine then, as you're right: it's better to keep the matters separate in this case.
Just to let you know my Debian mailserver (Postfix) is actually a Linux virtual machine running in my ESXi VMware host where all the steps you've described in your valuable raspberryPi tutorial apply identically and everything works exactly the same (except this way I don't run on an SDcard and have a bit more RAM and CPU leg room)
But yes, long-story-short, I'll install ownCloud on one of my spare raspberryPi machines instead and configure it like that, separate over port 4443.
- One last question, please: can I then (somehow?) configure perhaps an NFS share as main storage for the ownCloud machine, rather than reading and writing on the SDcard I'll use to boot my raspberryPi with?

Thank you once more,



Your tutorials on setting up Owncloud are detailed and complete however was wondering if this could be updated to version 9



Add new comment